LifecycleComponent { public void destroy() { lifecycleStrategy.invokeDestroyMethods(component); } LifecycleComponent(Object component);  LifecycleComponent(Object component, LifecycleMethodStrategy lifecycleStrategy); void initialize(); void destroy(); Object getComponent();  }
@Test public void invokesDestroyMethodWithDefaultLifecycleMethodStrategy() throws Exception { Resource instance = new Resource(); LifecycleComponent lifecycleComponent = new LifecycleComponent(instance); lifecycleComponent.destroy(); assertEquals(1, instance.destroyVisitsCounter.get()); }
@Test public void invokesDestroyMethodWithCustomLifecycleMethodStrategy() throws Exception { LifecycleMethodStrategy lifecycleMethodStrategy = mock(LifecycleMethodStrategy.class); Resource instance = new Resource(); LifecycleComponent lifecycleComponent = new LifecycleComponent(instance, lifecycleMethodStrategy); lifecycleComponent.destroy(); verify(lifecycleMethodStrategy).invokeDestroyMethods(instance); }