|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.googlecode.catchexception.throwable.apis.CatchThrowableHamcrestMatchers
public class CatchThrowableHamcrestMatchers
Provides some Hamcrest matchers to match some throwable properties.
EXAMPLE: // given an empty list
List myList = new ArrayList();
// when we try to get the first element of the list
catchThrowable(myList).get(1);
// then we expect an IndexOutOfBoundsThrowable with message "Index: 1, Size: 0"
assertThat(caughtThrowable(),
allOf(
is(IndexOutOfBoundsThrowable.class),
hasMessage("Index: 1, Size: 0"),
hasNoCause()
)
);
To combine the standard Hamcrest matchers, your custom matchers, these matchers, and other matcher collections (as
JUnitMatchers) in a single class follow the instructions outlined in Sugar generation.
Hint: This class might use hamsandwich in the future but as long as hamsandwich is not in any public maven repository, this class will not use hamsandwich.
| Constructor Summary | |
|---|---|
CatchThrowableHamcrestMatchers()
|
|
| Method Summary | ||
|---|---|---|
static
|
hasMessage(String expectedMessage)
EXAMPLE: |
|
static
|
hasMessageThat(org.hamcrest.Matcher<String> stringMatcher)
EXAMPLES: |
|
static
|
hasNoCause()
EXAMPLE: |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CatchThrowableHamcrestMatchers()
| Method Detail |
|---|
public static <T extends Throwable> org.hamcrest.Matcher<T> hasMessage(String expectedMessage)
assertThat(caughtThrowable(), hasMessage("Index: 9, Size: 9"));
T - the throwable subclassexpectedMessage - the expected throwable message
public static <T extends Throwable> org.hamcrest.Matcher<T> hasMessageThat(org.hamcrest.Matcher<String> stringMatcher)
assertThat(caughtThrowable(), hasMessageThat(is("Index: 9, Size: 9")));
assertThat(caughtThrowable(), hasMessageThat(containsString("Index: 9"))); // using JUnitMatchers
assertThat(caughtThrowable(), hasMessageThat(containsPattern("Index: \\d+"))); // using Mockito's Find
T - the throwable subclassstringMatcher - a string matcher
public static <T extends Throwable> org.hamcrest.Matcher<T> hasNoCause()
assertThat(caughtThrowable(), hasNoCause());
T - the throwable subclass
cause.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||