blob: 98ea75a1dbed685a4cabf9cae0aeb98b0496f13a (
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;
public class ExtraAsserts {
@SuppressWarnings("unchecked")
public static <T extends Throwable> T assertThrows(Class<T> exceptionType, Action action) {
try {
action.run();
throw new AssertionError("Expected exception");
} catch (Exception exception) {
if (exceptionType.isInstance(exception)) {
return (T)exception;
} else {
throw exception;
}
}
}
}
|