ConcordionInterceptor { @RuntimeType public static Object intercept(@FieldValue("executor") DecoratorExecutor executor, @FieldValue("bean") Object bean, @Origin Method method, @AllArguments Object[] args) throws Exception { final FeatureResolver resolver = FeatureResolver.newFeatureResolver(bean.getClass()).withTestMethod(method) .withDefaultCleanupPhase(CleanupPhase.NONE).build(); Object result = null; final TestInvocationImpl invocation = new TestInvocationImpl(bean, method, resolver); executor.processBefore(invocation); try { result = method.invoke(bean, args); } catch (final Exception e) { Exception cause = (Exception)e.getCause(); invocation.setTestException(cause); executor.processAfter(invocation); throw cause; } executor.processAfter(invocation); return result; } private  ConcordionInterceptor(); @RuntimeType static Object intercept(@FieldValue("executor") DecoratorExecutor executor, @FieldValue("bean") Object bean, @Origin Method method, @AllArguments Object[] args);  }
@Test public void testInterceptMethodInvocationWithoutExceptionThrown() throws Throwable { final Object[] args = new Object[0]; final Object res = ConcordionInterceptor.intercept(executor, delegate, method, args); assertThat(res, equalTo(RESULT)); final ArgumentCaptor<TestInvocation> beforeCaptor = ArgumentCaptor.forClass(TestInvocation.class); final ArgumentCaptor<TestInvocation> afterCaptor = ArgumentCaptor.forClass(TestInvocation.class); final InOrder inOrder = inOrder(executor, delegate); inOrder.verify(executor).processBefore(beforeCaptor.capture()); inOrder.verify(delegate).testMethod(); inOrder.verify(executor).processAfter(afterCaptor.capture()); final TestInvocation invocation1 = beforeCaptor.getValue(); final TestInvocation invocation2 = afterCaptor.getValue(); assertThat(invocation1, equalTo(invocation2)); assertThat(invocation1.getException().isPresent(), equalTo(Boolean.FALSE)); assertThat(invocation1.getContext(), equalTo(context)); assertThat(invocation1.getFeatureResolver().shouldCleanupAfter(), equalTo(Boolean.FALSE)); assertThat(invocation1.getFeatureResolver().shouldCleanupBefore(), equalTo(Boolean.FALSE)); assertThat(invocation1.getTestInstance().get(), equalTo(delegate)); assertThat(invocation1.getTestMethod().get(), equalTo(method)); }
@Test public void testInterceptMethodInvocationWithExceptionThrown() throws Throwable { final JpaUnitException exception = new JpaUnitException("some reason"); when(delegate.testMethod()).thenThrow(exception); final Object[] args = new Object[0]; try { ConcordionInterceptor.intercept(executor, delegate, method, args); fail("JpaUnitException expected"); } catch (final JpaUnitException e) { assertThat(e, equalTo(exception)); } final ArgumentCaptor<TestInvocation> beforeCaptor = ArgumentCaptor.forClass(TestInvocation.class); final ArgumentCaptor<TestInvocation> afterCaptor = ArgumentCaptor.forClass(TestInvocation.class); final InOrder inOrder = inOrder(executor, delegate); inOrder.verify(executor).processBefore(beforeCaptor.capture()); inOrder.verify(delegate).testMethod(); inOrder.verify(executor).processAfter(afterCaptor.capture()); final TestInvocation invocation1 = beforeCaptor.getValue(); final TestInvocation invocation2 = afterCaptor.getValue(); assertThat(invocation1, equalTo(invocation2)); assertThat(invocation1.getException().isPresent(), equalTo(Boolean.TRUE)); assertThat(invocation1.getContext(), equalTo(context)); assertThat(invocation1.getFeatureResolver().shouldCleanupAfter(), equalTo(Boolean.FALSE)); assertThat(invocation1.getFeatureResolver().shouldCleanupBefore(), equalTo(Boolean.FALSE)); assertThat(invocation1.getTestInstance().get(), equalTo(delegate)); assertThat(invocation1.getTestMethod().get(), equalTo(method)); }