JpaUnit implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback { @Override public void beforeEach(final ExtensionContext context) throws Exception { executor.processBefore(createTestMethodInvocation(context, true)); }  @Override void beforeAll(final ExtensionContext context); @Override void afterAll(final ExtensionContext context); @Override void beforeEach(final ExtensionContext context); @Override void afterEach(final ExtensionContext context);  }
@Test public void testBeforeEachTestDecoratorExecutionOrder() throws Exception { final JpaUnit unit = new JpaUnit(); unit.beforeEach(context); final InOrder order = inOrder(firstMethodDecorator, secondMethodDecorator); order.verify(firstMethodDecorator).beforeTest(notNull(TestInvocation.class)); order.verify(secondMethodDecorator).beforeTest(notNull(TestInvocation.class)); verifyZeroInteractions(firstClassDecorator, secondClassDecorator); }
@Test public void testBeforeEachInvocationArguments() throws Exception { when(DecoratorRegistrar.getMethodDecorators()).thenReturn(Arrays.asList(firstMethodDecorator)); final JpaUnit unit = new JpaUnit(); unit.beforeEach(context); final ArgumentCaptor<TestInvocation> invocationCaptor = ArgumentCaptor.forClass(TestInvocation.class); verify(firstMethodDecorator).beforeTest(invocationCaptor.capture()); final TestInvocation invocation = invocationCaptor.getValue(); assertNotNull(invocation.getContext()); assertThat(invocation.getTestMethod().get(), equalTo(getClass().getMethod("prepareMocks"))); assertThat(invocation.getTestClass(), equalTo(getClass())); assertFalse(invocation.getException().isPresent()); assertThat(invocation.getFeatureResolver().shouldCleanupAfter(), equalTo(Boolean.TRUE)); assertThat(invocation.getTestInstance(), notNullValue()); }