SecondLevelCacheDecorator implements TestMethodDecorator { @Override public void afterTest(final TestInvocation invocation) throws Exception { final EntityManagerFactory emf = (EntityManagerFactory) invocation.getContext().getData(Constants.KEY_ENTITY_MANAGER_FACTORY); evictCache(invocation.getFeatureResolver().shouldEvictCacheAfter(), emf); }  @Override int getPriority(); @Override void beforeTest(final TestInvocation invocation); @Override void afterTest(final TestInvocation invocation); @Override boolean isConfigurationSupported(final ExecutionContext ctx);  }
@Test public void testEvictionOfSecondLevelCacheIsRunInAfterTestPhaseIfConfiguredForIt() throws Throwable { when(resolver.shouldEvictCacheAfter()).thenReturn(Boolean.TRUE); final SecondLevelCacheDecorator fixture = new SecondLevelCacheDecorator(); fixture.afterTest(invocation); verify(cache).evictAll(); verify(emf, times(0)).close(); }
@Test public void testEvictionOfSecondLevelCacheIsNotRunInAfterTestPhaseIfNotConfiguredForIt() throws Throwable { when(resolver.shouldEvictCacheAfter()).thenReturn(Boolean.FALSE); final SecondLevelCacheDecorator fixture = new SecondLevelCacheDecorator(); fixture.afterTest(invocation); verifyNoMoreInteractions(cache, emf); }