blob: c5f16688f426063b83716dbc51b2e7cc9a901c81 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package org.zwobble.couscous.tests.util;
import org.zwobble.couscous.util.Action;
import org.zwobble.couscous.util.Casts;
import lombok.SneakyThrows;
public class ExtraAsserts {
@SneakyThrows
public static <T extends Throwable> T assertThrows(Class<T> exceptionType, Action action) {
try {
action.run();
throw new AssertionError("Expected exception");
} catch (Exception exception) {
return Casts.tryCast(exceptionType, exception)
.orElseThrow(() -> exception);
}
}
}
|