use of org.junit.runner.notification.Failure in project mockito by mockito.
the class ConsoleSpammingMockitoJUnitRunner method run.
@Override
public void run(RunNotifier notifier) {
RunListener listener = new RunListener() {
WarningsCollector warningsCollector;
@Override
public void testStarted(Description description) throws Exception {
warningsCollector = new WarningsCollector();
}
@Override
public void testFailure(Failure failure) throws Exception {
logger.log(warningsCollector.getWarnings());
}
};
notifier.addListener(listener);
runner.run(notifier);
}
use of org.junit.runner.notification.Failure in project mockito by mockito.
the class VerboseMockitoJUnitRunner method run.
@Override
public void run(RunNotifier notifier) {
//a listener that changes the failure's exception in a very hacky way...
RunListener listener = new RunListener() {
WarningsCollector warningsCollector;
@Override
public void testStarted(Description description) throws Exception {
warningsCollector = new WarningsCollector();
}
@Override
@SuppressWarnings("deprecation")
public void testFailure(final Failure failure) throws Exception {
String warnings = warningsCollector.getWarnings();
new JUnitFailureHacker().appendWarnings(failure, warnings);
}
};
notifier.addFirstListener(listener);
runner.run(notifier);
}
use of org.junit.runner.notification.Failure in project mockito by mockito.
the class JUnitFailureHackerTest method shouldNotAppendWhenNullWarnings.
@Test
public void shouldNotAppendWhenNullWarnings() throws Exception {
RuntimeException ex = new RuntimeException("foo");
Failure failure = new Failure(Description.EMPTY, ex);
//when
hacker.appendWarnings(failure, null);
//then
assertEquals(ex, failure.getException());
}
use of org.junit.runner.notification.Failure in project mockito by mockito.
the class JUnitFailureHackerTest method shouldReplaceException.
@Test
public void shouldReplaceException() throws Exception {
//given
RuntimeException actualExc = new RuntimeException("foo");
Failure failure = new Failure(Description.EMPTY, actualExc);
//when
hacker.appendWarnings(failure, "unused stubbing");
//then
assertEquals(ExceptionIncludingMockitoWarnings.class, failure.getException().getClass());
assertEquals(actualExc, failure.getException().getCause());
Assertions.assertThat(actualExc.getStackTrace()).isEqualTo(failure.getException().getStackTrace());
}
use of org.junit.runner.notification.Failure in project mockito by mockito.
the class JUnitFailureHackerTest method shouldPrintTheWarningSoICanSeeIt.
@Test
public void shouldPrintTheWarningSoICanSeeIt() throws Exception {
Failure failure = new Failure(Description.EMPTY, new RuntimeException("foo"));
//when
hacker.appendWarnings(failure, "unused stubbing blah");
//then
System.out.println(failure.getException());
}
Aggregations