|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.googlecode.catchexception.throwable.apis.BDDCatchThrowable
public class BDDCatchThrowable
Supports BDD-like approach to catch and verify throwables (given/when/then).
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 | |
|---|---|
BDDCatchThrowable()
|
|
| Method Summary | ||
|---|---|---|
static Throwable |
caughtThrowable()
Returns the throwable caught during the last call on the proxied object in the current thread. |
|
static org.assertj.core.api.AbstractThrowableAssert<?,? extends Throwable> |
then(Throwable actualThrowable)
Deprecated. Use BDDAssertions#then(Throwable) instead |
|
static void |
thenThrown(Class actualThrowableClazz)
Throws an assertion if no throwable is thrown or if an throwable of an unexpected type is thrown. |
|
static
|
when(T obj)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BDDCatchThrowable()
| Method Detail |
|---|
public static <T> T when(T obj)
T - The type of the given obj.obj - The instance that shall be proxied. Must not be null.
CatchThrowable.catchThrowable(Object)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.public static Throwable caughtThrowable()
when(Object). Returns null if the proxy
has not caught an throwable. Returns null if the caught throwable belongs to a class that is no longer
loaded.@Deprecated public static org.assertj.core.api.AbstractThrowableAssert<?,? extends Throwable> then(Throwable actualThrowable)
BDDAssertions#then(Throwable) instead
EXAMPLE: // given an empty list
List myList = new ArrayList();
// when we try to get first element of the list
when(myList).get(1);
// then we expect an IndexOutOfBoundsThrowable
then(caughtThrowable())
.isInstanceOf(IndexOutOfBoundsThrowable.class)
.hasMessage("Index: 1, Size: 0")
.hasMessageStartingWith("Index: 1")
.hasMessageEndingWith("Size: 0")
.hasMessageContaining("Size")
.hasNoCause();
actualThrowable - the value to be the target of the assertions methods.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||