I'm actually not sure if this is an IntelliJ thing or a Java thing.
I made a utility method that asserts that a specific type of exception is thrown:
public static <T, U extends Throwable> Throwable assertThrowsWithCause(
Class<T> expectedOuterExceptionType,
Class<U> expectedInnerExceptionType,
Executable executable) {
Exception outerException = assertThrows(Exception.class, executable);
assertEquals(expectedOuterExceptionType, outerException.getClass());
assertEquals(expectedInnerExceptionType, outerException.getCause().getClass());
return outerException.getCause();
}
It's used like this:
@Test
public void getMeasurementsConfig_configDoesNotExist() {
when(configManager.getConfig(sampleUUID.toString()))
.thenReturn(CompletableFuture.failedFuture(new NotFoundException("")));
assertThrowsWithCause(
CompletionException.class,
NotFoundException.class,
() -> configController
.getMeasurementsConfig(Context.ROOT, sampleRequest)
.toCompletableFuture().join());
}
But there is a warning on the method call:
Result of 'assertThrowsWithCause()' not thrown
Which I've learned I can suppress by adding
@Test
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void ...
on the calling method. But that means I'd have to add this to every single test across many files. How can I suppress this warning globally, in such a way it would be suppressed for everyone working on the project, i.e. not just in my local IntelliJ Settings? I tried suppressing on the called method, i.e.
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public static <T, U extends Throwable> Throwable assertThrowsWithCause(
but this did not have the same effect.