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