public class ErrorCollector extends Verifier
public static class UsesErrorCollectorTwice { @Rule public ErrorCollector collector= new ErrorCollector(); @Test public void example() { collector.addError(new Throwable("first thing went wrong")); collector.addError(new Throwable("second thing went wrong")); collector.checkThat(getResult(), not(containsString("ERROR!"))); // all lines will run, and then a combined failure logged at the end. } }
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.lang.Throwable> |
errors |
Constructor and Description |
---|
ErrorCollector() |
Modifier and Type | Method and Description |
---|---|
void |
addError(java.lang.Throwable error)
Adds a Throwable to the table.
|
<T> T |
checkSucceeds(java.util.concurrent.Callable<T> callable)
Adds to the table the exception, if any, thrown from
callable . |
<T> void |
checkThat(java.lang.String reason,
T value,
org.hamcrest.Matcher<T> matcher)
Adds a failure with the given
reason
to the table if matcher does not match value . |
<T> void |
checkThat(T value,
org.hamcrest.Matcher<T> matcher)
Adds a failure to the table if
matcher does not match value . |
void |
checkThrows(java.lang.Class<? extends java.lang.Throwable> expectedThrowable,
ThrowingRunnable runnable)
Adds a failure to the table if
runnable does not throw an
exception of type expectedThrowable when executed. |
protected void |
verify()
Override this to add verification logic.
|
protected void verify() throws java.lang.Throwable
Verifier
public void addError(java.lang.Throwable error)
public <T> void checkThat(T value, org.hamcrest.Matcher<T> matcher)
matcher
does not match value
.
Execution continues, but the test will fail at the end if the match fails.public <T> void checkThat(java.lang.String reason, T value, org.hamcrest.Matcher<T> matcher)
reason
to the table if matcher
does not match value
.
Execution continues, but the test will fail at the end if the match fails.public <T> T checkSucceeds(java.util.concurrent.Callable<T> callable)
callable
.
Execution continues, but the test will fail at the end if
callable
threw an exception.public void checkThrows(java.lang.Class<? extends java.lang.Throwable> expectedThrowable, ThrowingRunnable runnable)
runnable
does not throw an
exception of type expectedThrowable
when executed.
Execution continues, but the test will fail at the end if the runnable
does not throw an exception, or if it throws a different exception.expectedThrowable
- the expected type of the exceptionrunnable
- a function that is expected to throw an exception when executed