### Question:
PluginRegistryOSGIServiceLifecycleListener implements OSGIServiceLifecycleListener<PluginInterface> { @Override public void pluginAdded( PluginInterface serviceObject ) { try { OSGIPlugin osgiPlugin = (OSGIPlugin) serviceObject; Class<? extends PluginTypeInterface> pluginTypeFromPlugin = osgiPlugin.getPluginType(); try { registry.registerPlugin( pluginTypeFromPlugin, serviceObject ); openServiceTracker( pluginTypeFromPlugin, osgiPlugin); } catch ( KettlePluginException e ) { logger.error( e.getMessage(), e ); } } catch ( Exception e ) { logger.error( "Error notifying listener of plugin addition", e ); } } PluginRegistryOSGIServiceLifecycleListener( PluginRegistry registry ); @Override void pluginAdded( PluginInterface serviceObject ); @Override void pluginRemoved( PluginInterface serviceObject ); @Override void pluginChanged( PluginInterface serviceObject );  }### Answer:
@Test public void testPluginAddedNoException() throws KettlePluginException { final Class<? extends PluginTypeInterface> clazz = PluginTypeInterface.class; when( plugin.getPluginType() ).thenAnswer( new Answer<Object>() { @Override public Object answer( InvocationOnMock invocation ) throws Throwable { return clazz; } } ); pluginRegistryOSGIServiceLifecycleListener.pluginAdded( plugin ); verify( pluginRegistry ).registerPlugin( clazz, plugin ); }
@Test public void testPluginAddedKettlePluginException() throws KettlePluginException { final Class<? extends PluginTypeInterface> clazz = PluginTypeInterface.class; when( plugin.getPluginType() ).thenAnswer( new Answer<Object>() { @Override public Object answer( InvocationOnMock invocation ) throws Throwable { return clazz; } } ); KettlePluginException toBeThrown = new KettlePluginException(); doThrow( toBeThrown ).when( pluginRegistry ).registerPlugin( clazz, plugin ); pluginRegistryOSGIServiceLifecycleListener.pluginAdded( plugin ); verify( logger ).error( anyString(), eq( toBeThrown ) ); }
@Test public void testPluginAddedException() throws KettlePluginException { final Class<? extends PluginTypeInterface> clazz = PluginTypeInterface.class; when( plugin.getPluginType() ).thenAnswer( new Answer<Object>() { @Override public Object answer( InvocationOnMock invocation ) throws Throwable { return clazz; } } ); RuntimeException toBeThrown = new RuntimeException(); doThrow( toBeThrown ).when( pluginRegistry ).registerPlugin( clazz, plugin ); pluginRegistryOSGIServiceLifecycleListener.pluginAdded( plugin ); verify( logger ).error( anyString(), eq( toBeThrown ) ); }