### Question:
OSGIPluginTracker { public void addPluginLifecycleListener( Class clazzToTrack, OSGIServiceLifecycleListener listener ) { List<OSGIServiceLifecycleListener> list = listeners.get( clazzToTrack ); if ( list == null ) { list = new ArrayList<OSGIServiceLifecycleListener>(); listeners.put( clazzToTrack, list ); } list.add( listener ); } @VisibleForTesting protected  OSGIPluginTracker(); @VisibleForTesting protected  OSGIPluginTracker( AggregatingNotifierListener aggregatingNotifierListener ); static OSGIPluginTracker getInstance(); List<T> getServiceObjects( Class<T> clazz, Map<String, String> props ); T getBean( Class<T> clazz, Object serviceClass, String id ); Object getBeanPluginProperty( Class<? extends PluginTypeInterface> pluginType,
                                                                       Object instance, String prop ); ClassLoader getClassLoader( Object instance ); void setBeanFactoryLookup( BeanFactoryLocator lookup ); ProxyUnwrapper getProxyUnwrapper(); void setProxyUnwrapper( ProxyUnwrapper proxyUnwrapper ); BeanFactory findOrCreateBeanFactoryFor( Object serviceObject ); void shutdown(); void addPluginLifecycleListener( Class clazzToTrack, OSGIServiceLifecycleListener listener ); BundleContext getBundleContext(); void setBundleContext( BundleContext context ); boolean registerPluginClass( Class clazz ); void serviceChanged( Class<?> cls, LifecycleEvent evt, ServiceReference serviceObject ); boolean addDelayedServiceNotifierListener( DelayedServiceNotifierListener delayedServiceNotifierListener ); boolean removeDelayedServiceNotifierListener( DelayedServiceNotifierListener delayedServiceNotifierListener ); int getOutstandingServiceNotifierListeners();  }### Answer:
@Test public void testAddPluginLifecycleListener() { tracker.setBundleContext( bundleContext ); BeanFactoryLocator lookup = mock( BeanFactoryLocator.class ); tracker.setBeanFactoryLookup( lookup ); OSGIServiceLifecycleListener listener1 = mock( OSGIServiceLifecycleListener.class ); tracker.addPluginLifecycleListener( Object.class, listener1 ); OSGIServiceLifecycleListener listener2 = mock( OSGIServiceLifecycleListener.class ); tracker.addPluginLifecycleListener( Object.class, listener2 ); Object instance = new Object(); Bundle bundle = mock( Bundle.class ); ServiceReference serviceReference = mock( ServiceReference.class ); when( serviceReference.getBundle() ).thenReturn( bundle ); BeanFactory beanFactory = mock( BeanFactory.class ); when( lookup.getBeanFactory( bundle ) ).thenReturn( beanFactory ); when( bundleContext.getService( serviceReference ) ).thenReturn( instance ); tracker.serviceChanged( Object.class, LifecycleEvent.START, serviceReference ); verify( listener1 ).pluginAdded( instance ); verify( listener2 ).pluginAdded( instance ); }