### Question:
Activator implements BundleActivator, ServiceListener { @Override public void serviceChanged( ServiceEvent event ) { if (ServiceEvent.REGISTERED == event.getType()) { getActivatorHelper().verifyConfiguration(event.getServiceReference()); bundleContext.removeServiceListener(this); } }  @Override void serviceChanged( ServiceEvent event ); @Override void start( BundleContext bundleContext ); @Override void stop( BundleContext bundleContext );  }### Answer:
@Test public void shouldVerifyConfigurationWhenServiceEventRegisteredIsNotifiedAndRemoveServiceListener() throws Exception { final ActivatorHelper activatorHelper = mock(ActivatorHelper.class); Activator activator = new Activator() { @Override protected ActivatorHelper getActivatorHelper() { return activatorHelper; } }; BundleContext bundleContext = mock(BundleContext.class); injectBundleContextInto(activator, bundleContext); ServiceEvent serviceEvent = mock(ServiceEvent.class); when(serviceEvent.getType()).thenReturn(ServiceEvent.REGISTERED); ServiceReference aServiceReference = null; when(serviceEvent.getServiceReference()).thenReturn(aServiceReference ); activator.serviceChanged(serviceEvent); verify(activatorHelper).verifyConfiguration(aServiceReference); verify(bundleContext).removeServiceListener(activator); }
@Test public void shouldNotVerifyConfigurationAndRemoveServiceListenerWhenServiceEventRegisteredIsNotNotified() throws Exception { final ActivatorHelper activatorHelper = mock(ActivatorHelper.class); Activator activator = new Activator() { @Override protected ActivatorHelper getActivatorHelper() { return activatorHelper; } }; BundleContext bundleContext = mock(BundleContext.class); injectBundleContextInto(activator, bundleContext); ServiceEvent serviceEvent = mock(ServiceEvent.class); when(serviceEvent.getType()).thenReturn(ServiceEvent.MODIFIED); activator.serviceChanged(serviceEvent); verify(activatorHelper, never()).verifyConfiguration((ServiceReference)anyObject()); verify(bundleContext, never()).removeServiceListener((ServiceListener)anyObject()); }