@Test public void testRethrowsTearDownExceptionOnConsumerAndTearDownFailure() throws Exception { Exception consumerException = new Exception("whatever"); doThrow(consumerException).when(consumer).accept(jerseyTest); RuntimeException tearDownException = new RuntimeException("whatever"); doThrow(tearDownException).when(jerseyTest).tearDown(); try { runner.runJerseyTest(jerseyTest, consumer); fail("expected exception to be thrown"); } catch (Exception e) { assertSame(tearDownException, e); } } }
@Test public void testCallSetupConsumerAndTearDownInOrder() throws Exception { runner.runJerseyTest(jerseyTest, consumer); InOrder inOrder = Mockito.inOrder(jerseyTest, consumer); inOrder.verify(jerseyTest).setUp(); inOrder.verify(consumer).accept(jerseyTest); inOrder.verify(jerseyTest).tearDown(); }
@Test public void testCallsTearDownOnConsumerException() throws Exception { doThrow(new Exception("whatever")).when(consumer).accept(jerseyTest); try { runner.runJerseyTest(jerseyTest, consumer); fail("expected exception to be thrown"); } catch (Exception e) { ; } verify(jerseyTest).tearDown(); }
/** * <ol> * <li>calls {@link JerseyTest#setUp()} * <li>passes the initialized JerseyTest to the consumer. * <li>calls {@link JerseyTest#tearDown()} * </ol> * * @param jerseyTest * @param test * @throws Exception */ public void runJerseyTest(JerseyTest jerseyTest, ThrowingConsumer<JerseyTest> test) throws Exception { try { jerseyTest.setUp(); test.accept(jerseyTest); } finally { jerseyTest.tearDown(); } }
@Test public void testRethrowsExceptionOnConsumerFailure() throws Exception { Exception thrownException = new Exception("whatever"); doThrow(thrownException).when(consumer).accept(jerseyTest); try { runner.runJerseyTest(jerseyTest, consumer); fail("expected exception to be thrown"); } catch (Exception e) { assertSame(thrownException, e); } }
@Test public void testPassesJerseyTestToConsumer() throws Exception { runner.runJerseyTest(jerseyTest, consumer); verify(consumer).accept(jerseyTest); }