### Question:
KarafLifecycleListener implements IPhasedLifecycleListener<KettleLifecycleEvent> { public void setBundleContext( BundleContext bundleContext ) { this.bundleContext = bundleContext; bundleContext.registerService( ExecutorService.class, ExecutorUtil.getExecutor(), new Hashtable<>() ); this.frameworkStartLevel = bundleContext.getBundle( 0 ).adapt( FrameworkStartLevel.class ); maybeStartWatchers(); } @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 testSatisfied() throws Exception { final BaseCountdownLatchLifecycleManager<KettleLifecycleEvent> lifecycleManager = new BaseCountdownLatchLifecycleManager<KettleLifecycleEvent>() { @Override protected KettleLifecycleEvent getNotificationObject() { return KettleLifecycleEvent.INIT; } }; KarafLifecycleListener listener = new KarafLifecycleListener( 500 ); lifecycleManager.addLifecycleListener( listener ); lifecycleManager.advance(); assertTrue( lifecycleManager.getPhase() == 1 ); Thread t = new Thread( new Runnable() { @Override public void run() { try { lifecycleManager.advance(); } catch ( InterruptedException e ) { fail( "error in manager" ); e.printStackTrace(); } } }); t.start(); int fatalCount = 0; do { Thread.sleep( 10 ); } while ( t.getState() != Thread.State.WAITING && ++fatalCount < 10 ); assertTrue( t.getState() == Thread.State.WAITING ); assertEquals( 1, lifecycleManager.getPhase() ); IKarafFeatureWatcher featureWatcher = mock( IKarafFeatureWatcher.class ); IKarafBlueprintWatcher blueprintWatcher = mock( IKarafBlueprintWatcher.class ); BundleContext bundleContext = mockBundleContext( 100 ); ServiceReference reference = mock( ServiceReference.class ); ServiceReference reference2 = mock( ServiceReference.class ); when( bundleContext.getServiceReference( IKarafFeatureWatcher.class ) ).thenReturn( reference ); when( bundleContext.getService( reference )).thenReturn( featureWatcher ); when( bundleContext.getServiceReference( IKarafBlueprintWatcher.class ) ).thenReturn( reference2 ); when( bundleContext.getService( reference2 )).thenReturn( blueprintWatcher ); listener.setBundleContext( bundleContext ); t.join(); assertEquals( 2, lifecycleManager.getPhase() ); }