### Question:
KarafLifecycleListener implements IPhasedLifecycleListener<KettleLifecycleEvent> { @Override public void onPhaseChange( final IPhasedLifecycleEvent<KettleLifecycleEvent> event ) { this.event = event; if ( event.getNotificationObject().equals( KettleLifecycleEvent.INIT ) ) { listenerActive.set( true ); startTimeoutThread(); maybeStartWatchers(); } else { event.accept(); } } @VisibleForTesting  KarafLifecycleListener(); @VisibleForTesting  KarafLifecycleListener( long timeout ); @VisibleForTesting  KarafLifecycleListener( long timeout, OSGIPluginTracker osgiPluginTracker ); @VisibleForTesting  KarafLifecycleListener( long timeout, OSGIPluginTracker osgiPluginTracker, int frameworkBeginningStartLevel ); static synchronized KarafLifecycleListener getInstance(); @Override void onPhaseChange( final IPhasedLifecycleEvent<KettleLifecycleEvent> event ); void setBundleContext( BundleContext bundleContext );  }### Answer:
@Test public void testDelayedServiceNotifierListener() { IPhasedLifecycleEvent<KettleLifecycleEvent> iPhasedLifecycleEvent = mock( IPhasedLifecycleEvent.class ); when( iPhasedLifecycleEvent.getNotificationObject() ).thenReturn( KettleLifecycleEvent.INIT ); when( bundleContext.getServiceReference( IKarafFeatureWatcher.class ) ).thenReturn( featureWatcherServiceReference ); when( bundleContext.getServiceReference( IKarafBlueprintWatcher.class ) ).thenReturn( blueprintWatcherServiceReference ); when( osgiPluginTracker.getOutstandingServiceNotifierListeners() ).thenReturn( 1 ).thenReturn( 0 ); karafLifecycleListener.onPhaseChange( iPhasedLifecycleEvent ); ArgumentCaptor<DelayedServiceNotifierListener> delayedServiceNotifierListenerArgumentCaptor = ArgumentCaptor.forClass( DelayedServiceNotifierListener.class ); verify( osgiPluginTracker, timeout( (int) TimeUnit.SECONDS.toMillis( 5 ) ) ).addDelayedServiceNotifierListener( delayedServiceNotifierListenerArgumentCaptor.capture() ); verify( iPhasedLifecycleEvent, never() ).accept(); delayedServiceNotifierListenerArgumentCaptor.getValue().onRun( null, null ); verify( iPhasedLifecycleEvent ).accept(); delayedServiceNotifierListenerArgumentCaptor.getValue().onRun( null, null ); verify( iPhasedLifecycleEvent, times( 1 ) ).accept(); }