public class BDDCatchThrowable extends Object
import static com.googlecode.catchexception.throwable.apis
.BDDCatchThrowable.*;
// given an empty list
List myList = new ArrayList();
// when we try to get the first element of the list
when(myList).get(1);
// then we expect an IndexOutOfBoundsThrowable
then(caughtThrowable())
.isInstanceOf(IndexOutOfBoundsThrowable.class)
.hasMessage("Index: 1, Size: 0")
.hasNoCause();
// then we expect an IndexOutOfBoundsThrowable (alternatively)
thenThrown(IndexOutOfBoundsThrowable.class);
| Constructor and Description |
|---|
BDDCatchThrowable() |
| Modifier and Type | Method and Description |
|---|---|
static Throwable |
caughtThrowable()
Returns the throwable caught during the last call on the proxied object in the current thread.
|
static <T extends Throwable> |
caughtThrowable(Class<T> caughtThrowableType) |
static void |
thenThrown(Class actualThrowableClazz)
Throws an assertion if no throwable is thrown or if an throwable of an unexpected type is thrown.
|
static void |
when(ThrowingCallable actor) |
public BDDCatchThrowable()
public static void when(ThrowingCallable actor)
actor - The instance that shall be proxied. Must not be null.CatchThrowable.catchThrowable(ThrowingCallable)public static Throwable caughtThrowable()
when(ThrowingCallable). Returns null the proxy
has not caught an throwable. Returns null if the caught throwable belongs to a class that is no longer
loaded.public static <T extends Throwable> T caughtThrowable(Class<T> caughtThrowableType)
public static void thenThrown(Class actualThrowableClazz)
EXAMPLE:
// given a list with nine members
List myList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
// when we try to get the 500th member of the fellowship
when(myList).get(500);
// then we expect an IndexOutOfBoundsThrowable
thenThrown(IndexOutOfBoundsThrowable.class);
actualThrowableClazz - the expected type of the caught throwable.Copyright © 2019. All rights reserved.