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);
}
}
Aggregations