Neo4JDbDecorator implements TestMethodDecorator { @Override public void afterTest(final TestInvocation invocation) throws Exception { final ExecutionContext context = invocation.getContext(); final Neo4JDbFeatureExecutor dbFeatureExecutor = new Neo4JDbFeatureExecutor(invocation.getFeatureResolver(), context.getDescriptor().getClasses()); try (final Connection connection = (Connection) context.getData(Constants.KEY_CONNECTION)) { dbFeatureExecutor.executeAfterTest(connection, invocation.getException().isPresent()); } finally { context.storeData(Constants.KEY_CONNECTION, null); } }  @Override int getPriority(); @Override boolean isConfigurationSupported(final ExecutionContext ctx); @Override void beforeTest(final TestInvocation invocation); @Override void afterTest(final TestInvocation invocation);  }
@Test public void testAfterTestExecutesWithoutErrors() throws Exception { decorator.afterTest(invocation); verify(connection).close(); verify(executor).executeAfterTest(eq(connection), eq(Boolean.FALSE)); verify(ctx).storeData(eq(Constants.KEY_CONNECTION), isNull()); verifyZeroInteractions(dataSource); }
@Test public void testAfterTestExecutesWithErrors() throws Exception { doThrow(RuntimeException.class).when(executor).executeAfterTest(eq(connection), eq(Boolean.FALSE)); try { decorator.afterTest(invocation); fail("Exception expected"); } catch (final RuntimeException e) { } verify(connection).close(); verify(ctx).storeData(eq(Constants.KEY_CONNECTION), isNull()); verifyZeroInteractions(dataSource); }