@Test public void shouldWorkWithExpectedException() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); Result result = run(adaptor, ClassWithArquillianRunnerWithExpectedException.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.BEFORE, Cycle.TEST, Cycle.AFTER, Cycle.AFTER_CLASS); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldCallAfterWhenBeforeThrowsException() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); throwException(Cycle.BEFORE, new Throwable()); Result result = run(adaptor, ClassWithArquillianRunner.class); Assert.assertFalse(result.wasSuccessful()); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.AFTER_CLASS, Cycle.BEFORE, Cycle.AFTER); assertCycle(0, Cycle.TEST); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
public void stop() throws LifecycleException { JUnitIntegrationTestCase.wasCalled("stop"); }
@Test public void shouldCallAllMethodsWithRealAdapter() throws Exception { System.setProperty("arquillian.debug", "true"); TestRunnerAdaptor adaptor = spy(TestRunnerAdaptorBuilder.build()); Result result = run(adaptor, ArquillianClass1.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(1, Cycle.values()); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); } }
@Test public void shouldOnlyCallBeforeAfterSuiteOnce() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); Result result = run(adaptor, ClassWithArquillianRunner.class, ClassWithArquillianRunner.class, ClassWithArquillianRunner.class, ClassWithArquillianRunner.class); Assert.assertTrue(result.wasSuccessful()); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldHandleTheLifecycleCorrectlyOnMultipleTestRunsWithExceptions() throws Throwable { JUnitCore runner = new JUnitCore(); Result result = runner.run( Request.classes(ArquillianClass1.class, ArquillianClass1.class)); Assert.assertEquals( "Verify that both exceptions thrown bubbled up", 2, result.getFailureCount()); // Exceptions returned are wrapped in a InvocationException and InvocatioTargetException, verify the cause Assert.assertEquals( "Verify exception thrown", "deploy", result.getFailures().get(0).getException().getMessage()); Assert.assertEquals( "Verify exception thrown", "undeploy", result.getFailures().get(1).getException().getMessage()); Assert.assertFalse(result.wasSuccessful()); assertCallbacks(); }
@Test public void shouldCallAllMethodsWithRealAdapter() throws Exception { System.setProperty("arquillian.debug", "true"); TestRunnerAdaptor adaptor = spy(TestRunnerAdaptorBuilder.build()); Result result = run(adaptor, ArquillianClass1.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(1, Cycle.values()); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); } }
@Test public void shouldOnlyCallBeforeAfterSuiteOnce() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); Result result = run(adaptor, ClassWithArquillianRunner.class, ClassWithArquillianRunner.class, ClassWithArquillianRunner.class, ClassWithArquillianRunner.class); Assert.assertTrue(result.wasSuccessful()); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldWorkWithExpectedException() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); Result result = run(adaptor, ClassWithArquillianRunnerWithExpectedException.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.BEFORE, Cycle.TEST, Cycle.AFTER, Cycle.AFTER_CLASS); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldCallAfterClassWhenBeforeThrowsException() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); throwException(Cycle.BEFORE_CLASS, new Throwable()); Result result = run(adaptor, ClassWithArquillianRunner.class); Assert.assertFalse(result.wasSuccessful()); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.AFTER_CLASS); assertCycle(0, Cycle.BEFORE, Cycle.AFTER, Cycle.TEST); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldNotCallAnyMethodsWithoutLifecycleHandlers() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); when(adaptor.test(isA(TestMethodExecutor.class))).thenReturn(TestResult.passed()); Result result = run(adaptor, ClassWithArquillianRunner.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(0, Cycle.basics()); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
public void start() throws LifecycleException { JUnitIntegrationTestCase.wasCalled("start"); }
@Test public void shouldWorkWithExpectedExceptionRule() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); Result result = run(adaptor, ClassWithArquillianRunnerWithExpectedExceptionRule.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.BEFORE, Cycle.TEST, Cycle.AFTER, Cycle.AFTER_CLASS); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldCallAfterClassWhenBeforeThrowsException() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); throwException(Cycle.BEFORE_CLASS, new Throwable()); Result result = run(adaptor, ClassWithArquillianRunner.class); Assert.assertFalse(result.wasSuccessful()); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.AFTER_CLASS); assertCycle(0, Cycle.BEFORE, Cycle.AFTER, Cycle.TEST); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldNotCallAnyMethodsWithoutLifecycleHandlers() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); when(adaptor.test(isA(TestMethodExecutor.class))).thenReturn(TestResult.passed()); Result result = run(adaptor, ClassWithArquillianRunner.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(0, Cycle.basics()); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
public void setup(TestContainerConfiguration configuration) { JUnitIntegrationTestCase.wasCalled("setup"); }
@Test public void shouldWorkWithExpectedExceptionRule() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); Result result = run(adaptor, ClassWithArquillianRunnerWithExpectedExceptionRule.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.BEFORE, Cycle.TEST, Cycle.AFTER, Cycle.AFTER_CLASS); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldCallAfterWhenBeforeThrowsException() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); executeAllLifeCycles(adaptor); throwException(Cycle.BEFORE, new Throwable()); Result result = run(adaptor, ClassWithArquillianRunner.class); Assert.assertFalse(result.wasSuccessful()); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.AFTER_CLASS, Cycle.BEFORE, Cycle.AFTER); assertCycle(0, Cycle.TEST); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldThrowMultipleExceptionIfFailureInBeforeAndAfterRule() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); doAnswer(new ThrowsException(new RuntimeException("AfterRuleException"))).when(adaptor) .fireCustomLifecycle(isA(AfterRules.class)); doAnswer(new ExecuteLifecycle()).when(adaptor).fireCustomLifecycle(isA(BeforeRules.class)); doAnswer(new ExecuteLifecycle()).when(adaptor).beforeClass(any(Class.class), any(LifecycleMethodExecutor.class)); doAnswer(new ExecuteLifecycle()).when(adaptor).afterClass(any(Class.class), any(LifecycleMethodExecutor.class)); doAnswer(new ExecuteLifecycle()).when(adaptor) .before(any(Object.class), any(Method.class), any(LifecycleMethodExecutor.class)); doAnswer(new ExecuteLifecycle()).when(adaptor) .after(any(Object.class), any(Method.class), any(LifecycleMethodExecutor.class)); doAnswer(new TestExecuteLifecycle(TestResult.passed())).when(adaptor).test(any(TestMethodExecutor.class)); Result result = run(adaptor, ClassWithArquillianRunnerWithExceptionInAfterAndAfterRule.class); Assert.assertFalse(result.wasSuccessful()); Assert.assertEquals(2, result.getFailureCount()); Assert.assertTrue(result.getFailures().get(0).getMessage().equals("AfterException")); Assert.assertTrue(result.getFailures().get(1).getMessage().equals("AfterRuleException")); assertCycle(1, Cycle.basics()); verify(adaptor, times(1)).fireCustomLifecycle(isA(BeforeRules.class)); verify(adaptor, times(1)).fireCustomLifecycle(isA(AfterRules.class)); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); } }
public void undeploy(Archive<?> deployment) throws DeploymentException { JUnitIntegrationTestCase.wasCalled("undeploy"); if(numberOfTimesDeployed == 1) { throw new RuntimeException("undeploy"); } } }