### Question:
PluginRegistryOSGIServiceLifecycleListener implements OSGIServiceLifecycleListener<PluginInterface> { @Override public void pluginRemoved( PluginInterface serviceObject ) { try { OSGIPlugin osgiPlugin = (OSGIPlugin) serviceObject; Class<? extends PluginTypeInterface> pluginTypeFromPlugin = osgiPlugin.getPluginType(); registry.removePlugin( pluginTypeFromPlugin, serviceObject ); } catch ( Exception e ) { logger.error( "Error notifying listener of plugin removal", e ); } } PluginRegistryOSGIServiceLifecycleListener( PluginRegistry registry ); @Override void pluginAdded( PluginInterface serviceObject ); @Override void pluginRemoved( PluginInterface serviceObject ); @Override void pluginChanged( PluginInterface serviceObject );  }### Answer:
@Test public void testPluginRemovedNoException() 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.pluginRemoved( plugin ); verify( pluginRegistry ).removePlugin( clazz, plugin ); }
@Test public void testPluginRemovedException() 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 ).removePlugin( clazz, plugin ); pluginRegistryOSGIServiceLifecycleListener.pluginRemoved( plugin ); verify( logger ).error( anyString(), eq( toBeThrown ) ); }