Class BDDCatchThrowable
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Throwable
Returns the throwable caught during the last call on the proxied object in the current thread.static <T extends Throwable>
TcaughtThrowable
(Class<T> caughtThrowableType) Deprecated, for removal: This API element is subject to removal in a future version.Use caghtThrowable() instead as the passed argument does nothingstatic 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) When.
-
Constructor Details
-
BDDCatchThrowable
public BDDCatchThrowable()
-
-
Method Details
-
when
When.- Parameters:
actor
- The instance that shall be proxied. Must not benull
.- See Also:
-
caughtThrowable
Returns the throwable caught during the last call on the proxied object in the current thread.- Returns:
- Returns the throwable caught during the last call on the proxied object in the current thread - if the
call was made through a proxy that has been created via
when(ThrowingCallable)
. Returns null the proxy has not caught an throwable. Returns null if the caught throwable belongs to a class that is no longerloaded
.
-
caughtThrowable
@Deprecated(since="2.3.0", forRemoval=true) public static <T extends Throwable> T caughtThrowable(Class<T> caughtThrowableType) Deprecated, for removal: This API element is subject to removal in a future version.Use caghtThrowable() instead as the passed argument does nothingCaught throwable.- Type Parameters:
T
- the generic type- Parameters:
caughtThrowableType
- the caught throwable type- Returns:
- the t
-
thenThrown
Throws an assertion if no throwable is thrown or if an throwable of an unexpected type is thrown.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);
- Parameters:
actualThrowableClazz
- the expected type of the caught throwable.
-