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

import org.zwobble.couscous.util.Action;
import org.zwobble.couscous.util.Casts;

public class ExtraAsserts {
    public static <T extends Throwable> T assertThrows(Class<T> exceptionType, Action action) throws T {
        try {
            action.run();
            throw new AssertionError("Expected exception");
        } catch (RuntimeException exception) {
            return Casts.tryCast(exceptionType, exception)
                .orElseThrow(() -> exception);
        }
    }
}