protected void executeAllLifeCycles(TestRunnerAdaptor adaptor) throws Exception { doAnswer(new ExecuteLifecycle()).when(adaptor).fireCustomLifecycle(isA(BeforeRules.class)); doAnswer(new ExecuteLifecycle()).when(adaptor).fireCustomLifecycle(isA(AfterRules.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)); }
@Override public void interceptFeatureMethod(final IMethodInvocation invocation) throws Throwable { TestResult result = getTestRunner().test(new TestMethodExecutor() { @Override public Method getMethod() { return invocation.getFeature().getFeatureMethod().getReflection(); } @Override public Object getInstance() { return invocation.getTarget(); } @Override public void invoke(Object... parameters) throws Throwable { invocation.proceed(); } }); if (result.getThrowable() != null) { throw result.getThrowable(); } }
protected void executeAllLifeCycles(TestRunnerAdaptor adaptor) throws Exception { 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(new TestResult(Status.PASSED))).when(adaptor) .test(any(TestMethodExecutor.class)); }
@Override public void interceptFeatureMethod(final IMethodInvocation invocation) throws Throwable { TestResult result = getTestRunner().test(new TestMethodExecutor() { @Override public Method getMethod() { return invocation.getFeature().getFeatureMethod().getReflection(); } @Override public Object getInstance() { return invocation.getTarget(); } @Override public void invoke(Object... parameters) throws Throwable { invocation.proceed(); } }); if(result.getThrowable() != null) { throw result.getThrowable(); } }
protected void executeAllLifeCycles(TestRunnerAdaptor adaptor) throws Exception { 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(new TestResult(Status.PASSED))).when(adaptor) .test(any(TestMethodExecutor.class)); }
protected void executeAllLifeCycles(TestRunnerAdaptor adaptor) throws Exception { doAnswer(new ExecuteLifecycle()).when(adaptor).fireCustomLifecycle(isA(BeforeRules.class)); doAnswer(new ExecuteLifecycle()).when(adaptor).fireCustomLifecycle(isA(AfterRules.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)); }
protected void executeAllLifeCycles(TestRunnerAdaptor adaptor) throws Exception { doAnswer(new ExecuteLifecycle()).when(adaptor).fireCustomLifecycle(isA(BeforeRules.class)); doAnswer(new ExecuteLifecycle()).when(adaptor).fireCustomLifecycle(isA(AfterRules.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)); }
void invoke(final TestRunnerAdaptor adaptor, final FrameworkMethod method, final Object test) throws Throwable { TestResult result = adaptor.test(new TestMethodExecutor() { @Override public void invoke(Object... parameters) throws Throwable { invokeMethod(parameters); } public Method getMethod() { return method.getMethod(); } public Object getInstance() { return test; } }); Throwable throwable = result.getThrowable(); if (throwable != null) { if (result.getStatus() == TestResult.Status.SKIPPED) { if (throwable instanceof SkippedTestExecutionException) { result.setThrowable(new AssumptionViolatedException(throwable.getMessage())); } } throw result.getThrowable(); } }
protected void executeAllLifeCycles(TestRunnerAdaptor adaptor) throws Exception { doAnswer(new ExecuteLifecycle()).when(adaptor).fireCustomLifecycle(isA(BeforeRules.class)); doAnswer(new ExecuteLifecycle()).when(adaptor).fireCustomLifecycle(isA(AfterRules.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)); }
void invoke(final TestRunnerAdaptor adaptor, final FrameworkMethod method, final Object test) throws Throwable { TestResult result = adaptor.test(new TestMethodExecutor() { @Override public void invoke(Object... parameters) throws Throwable { invokeMethod(parameters); } public Method getMethod() { return method.getMethod(); } public Object getInstance() { return test; } }); Throwable throwable = result.getThrowable(); if (throwable != null) { if (result.getStatus() == TestResult.Status.SKIPPED) { if (throwable instanceof SkippedTestExecutionException) { result.setThrowable(new AssumptionViolatedException(throwable.getMessage())); } } throw result.getThrowable(); } }
protected void executeAllLifeCycles(TestRunnerAdaptor adaptor) throws Exception { doAnswer(new ExecuteLifecycle(Cycle.BEFORE_SUITE)).when(adaptor).beforeSuite(); doAnswer(new ExecuteLifecycle(Cycle.AFTER_SUITE)).when(adaptor).afterSuite(); doAnswer(new ExecuteLifecycle(Cycle.BEFORE_CLASS)).when(adaptor) .beforeClass(any(Class.class), any(LifecycleMethodExecutor.class)); doAnswer(new ExecuteLifecycle(Cycle.AFTER_CLASS)).when(adaptor) .afterClass(any(Class.class), any(LifecycleMethodExecutor.class)); doAnswer(new ExecuteLifecycle(Cycle.BEFORE)).when(adaptor) .before(any(Object.class), any(Method.class), any(LifecycleMethodExecutor.class)); doAnswer(new ExecuteLifecycle(Cycle.AFTER)).when(adaptor) .after(any(Object.class), any(Method.class), any(LifecycleMethodExecutor.class)); doAnswer(new TestExecuteLifecycle(new TestResult(Status.PASSED))).when(adaptor) .test(any(TestMethodExecutor.class)); }
@Test public void shouldCallBeforeClassAndAfterClassWithoutLifecycleHandlers() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); when(adaptor.test(isA(TestMethodExecutor.class))).thenReturn(TestResult.passed()); Result result = run(adaptor, ClassWithArquillianClassAndMethodRule.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.AFTER_CLASS); assertCycle(0, Cycle.BEFORE, Cycle.AFTER, Cycle.AFTER_RULE, Cycle.BEFORE_RULE); verify(adaptor, times(1)).beforeSuite(); verify(adaptor, times(1)).afterSuite(); }
@Test public void shouldCallBeforeClassAndAfterClassWithoutLifecycleHandlers() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); when(adaptor.test(isA(TestMethodExecutor.class))).thenReturn(TestResult.passed()); Result result = run(adaptor, ClassWithArquillianClassAndMethodRule.class); Assert.assertTrue(result.wasSuccessful()); assertCycle(1, Cycle.BEFORE_CLASS, Cycle.AFTER_CLASS); assertCycle(0, Cycle.BEFORE, Cycle.AFTER, Cycle.AFTER_RULE, Cycle.BEFORE_RULE); 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(); }
@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(); }
@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, ClassWithArquillianClassAndMethodRuleWithExceptionInAfterAndAfterRule.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(); }
@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(); } }
@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, ClassWithArquillianClassAndMethodRuleWithExceptionInAfterAndAfterRule.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(); }
@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(); } }
@Test @Ignore("ARQ-582") public void shouldNotCallAnyMethodsWithoutLifecycleHandlers() throws Exception { TestRunnerAdaptor adaptor = mock(TestRunnerAdaptor.class); when(adaptor.test(isA(TestMethodExecutor.class))).thenReturn(new TestResult(Status.PASSED)); TestListenerAdapter result = run(adaptor, ArquillianClass1.class); Assert.assertTrue(wasSuccessful(result)); assertCycle(0, Cycle.values()); assertCycle(1, Cycle.BEFORE_SUITE, Cycle.AFTER_SUITE); }