Search in sources :

Example 26 with Failure

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);
}
Also used : Description(org.junit.runner.Description) WarningsCollector(org.mockito.internal.debugging.WarningsCollector) Failure(org.junit.runner.notification.Failure) RunListener(org.junit.runner.notification.RunListener)

Example 27 with Failure

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);
}
Also used : Description(org.junit.runner.Description) JUnitFailureHacker(org.mockito.internal.junit.util.JUnitFailureHacker) WarningsCollector(org.mockito.internal.debugging.WarningsCollector) Failure(org.junit.runner.notification.Failure) RunListener(org.junit.runner.notification.RunListener)

Example 28 with Failure

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());
}
Also used : Failure(org.junit.runner.notification.Failure) Test(org.junit.Test)

Example 29 with Failure

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());
}
Also used : Failure(org.junit.runner.notification.Failure) Test(org.junit.Test)

Example 30 with Failure

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());
}
Also used : Failure(org.junit.runner.notification.Failure) Test(org.junit.Test)

Aggregations

Failure (org.junit.runner.notification.Failure)190 Test (org.junit.Test)101 Result (org.junit.runner.Result)88 Description (org.junit.runner.Description)38 IOException (java.io.IOException)32 UnitTest (org.apache.geode.test.junit.categories.UnitTest)27 JUnitCore (org.junit.runner.JUnitCore)21 FileInputStream (java.io.FileInputStream)20 InputStream (java.io.InputStream)20 RunListener (org.junit.runner.notification.RunListener)18 ArrayList (java.util.ArrayList)10 ComparisonFailure (org.junit.ComparisonFailure)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)7 RunNotifier (org.junit.runner.notification.RunNotifier)7 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)6 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)5 Before (org.junit.Before)5 Request (org.junit.runner.Request)5 Runner (org.junit.runner.Runner)5