EntityManagerFactoryDecorator implements TestClassDecorator { @Override public void afterAll(final TestInvocation invocation) throws Exception { ExecutionContext context = invocation.getContext(); final EntityManager em = (EntityManager) context.getData(Constants.KEY_ENTITY_MANAGER); context.storeData(Constants.KEY_ENTITY_MANAGER, null); if (em != null) { em.close(); } final EntityManagerFactory emf = (EntityManagerFactory) context.getData(Constants.KEY_ENTITY_MANAGER_FACTORY); context.storeData(Constants.KEY_ENTITY_MANAGER_FACTORY, null); emf.close(); }  @Override int getPriority(); @Override void beforeAll(final TestInvocation invocation); @Override void afterAll(final TestInvocation invocation); @Override boolean isConfigurationSupported(final ExecutionContext ctx);  }
@Test public void testAfterAll() throws Throwable { when(ctx.getData(Constants.KEY_ENTITY_MANAGER_FACTORY)).thenReturn(factory); final EntityManagerFactoryDecorator decorator = new EntityManagerFactoryDecorator(); decorator.afterAll(invocation); verify(ctx).storeData(eq(Constants.KEY_ENTITY_MANAGER_FACTORY), eq(null)); verify(factory).close(); }