T - expected type of thrown exceptionpublic abstract class SafeCheck<T extends Throwable> extends Object implements Check
Check interface. Ensures that thrown exception has expected type
and pass it to safeCheck(Throwable) method. Should be used for anonymous classes.
Commonly used in conjunction with Assertj assertions in callback's body.
Usage with CheckExpectedException rule:
@Rule
public CheckExpectedException thrown = CheckExpectedException.none();
@Test
public void test_state_with_type_safe_check() throws NotEnoughMoney {
thrown.check(new SafeCheck() {
protected void safeCheck(NotEnoughMoney notEnoughMoney) {
assertThat(notEnoughMoney.getLackingMoney()).isEqualTo(3); //assert custom exception
}
});
}
| Modifier | Constructor and Description |
|---|---|
protected |
SafeCheck()
Constructs new instance, most convenient constructor.
|
protected |
SafeCheck(Class<T> expectedType)
Constructs new instance for expected exception's type.
|
protected |
SafeCheck(ClassFinder finder)
Construct new instance for expected exception's type finder.
|
protected SafeCheck()
protected SafeCheck(Class<T> expectedType)
expectedType - expected thrown exception's typeprotected SafeCheck(ClassFinder finder)
finder - class finder to find concrete class of thrown exceptionpublic final void check(Throwable exception)
safeCheck(Throwable) method.protected abstract void safeCheck(T exception)
check(Throwable).exception - thrown exceptionCopyright © 2014. All rights reserved.