Search in sources :

Example 1 with CancellableRequestFactory

use of com.google.testing.junit.runner.internal.junit4.CancellableRequestFactory in project bazel by bazelbuild.

the class JUnit4RunnerTest method testInterruptedTest.

@Test
public void testInterruptedTest() throws Exception {
    config = createConfig();
    mockRunListener = mock(RunListener.class);
    JUnit4BazelMock component = createComponent(SampleSuite.class);
    JUnit4Runner runner = component.runner();
    final CancellableRequestFactory requestFactory = component.cancellableRequestFactory();
    Description testDescription = Description.createTestDescription(SamplePassingTest.class, "testThatAlwaysPasses");
    doAnswer(cancelTestRun(requestFactory)).when(mockRunListener).testStarted(testDescription);
    try {
        runner.run();
        fail("exception expected");
    } catch (RuntimeException e) {
        assertEquals("Test run interrupted", e.getMessage());
        assertTrue("Expected cause to be a StoppedByUserException", e.getCause() instanceof StoppedByUserException);
        InOrder inOrder = inOrder(mockRunListener);
        inOrder.verify(mockRunListener).testRunStarted(any(Description.class));
        inOrder.verify(mockRunListener).testStarted(testDescription);
        inOrder.verify(mockRunListener).testFinished(testDescription);
    }
}
Also used : Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) StoppedByUserException(org.junit.runner.notification.StoppedByUserException) CancellableRequestFactory(com.google.testing.junit.runner.internal.junit4.CancellableRequestFactory) RunListener(org.junit.runner.notification.RunListener) SettableCurrentRunningTest(com.google.testing.junit.runner.internal.junit4.SettableCurrentRunningTest) CurrentRunningTest(com.google.testing.junit.runner.util.CurrentRunningTest) Test(org.junit.Test)

Aggregations

CancellableRequestFactory (com.google.testing.junit.runner.internal.junit4.CancellableRequestFactory)1 SettableCurrentRunningTest (com.google.testing.junit.runner.internal.junit4.SettableCurrentRunningTest)1 CurrentRunningTest (com.google.testing.junit.runner.util.CurrentRunningTest)1 Test (org.junit.Test)1 Description (org.junit.runner.Description)1 RunListener (org.junit.runner.notification.RunListener)1 StoppedByUserException (org.junit.runner.notification.StoppedByUserException)1 InOrder (org.mockito.InOrder)1