aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/couscous/tests/util/ExtraAsserts.java
blob: 8b1c16caa56fafde734e9560e50b6e97c00a217f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package org.zwobble.couscous.tests.util;

public class ExtraAsserts {
    public interface Action {
        void run();
    }
    
    @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;
            }
        }
    }
}