AnnotatedLifecycleMethodStrategy implements LifecycleMethodStrategy { @Override public void invokeDestroyMethods(Object o) { final Class<?> aClass = o.getClass(); Method[] destroyMethods = null; try { destroyMethods = destroyMethodsCache.get(aClass); } catch (ExecutionException e) { Throwables.propagate(e); } if (destroyMethods != null && destroyMethods.length > 0) { doInvokeLifecycleMethods(o, destroyMethods); } } AnnotatedLifecycleMethodStrategy(); @Override void invokeInitializeMethods(Object o); @Override void invokeDestroyMethods(Object o);  }
@Test public void invokesDestroyMethods() throws Exception { lifecycleMethodStrategy.invokeDestroyMethods(new WithLifeCycleAnnotation()); assertTrue(String.format("Only \"destroy\" and \"nonPublicDestroy\" methods are expected to be invoked but %s were invoked", callAssertion), callAssertion.size() == 2 && callAssertion.containsAll(newArrayList("destroy", "nonPublicDestroy"))); }
@Test public void wrapsRuntimeExceptionThrownByDestroyMethodWithInternalException() { thrown.expect(lifecycleMethodInvocationExceptionMatcher("destroy fails")); lifecycleMethodStrategy.invokeDestroyMethods(new LifeCycleMethodsThrowsRuntimeException()); }