### Question:
ManagedProcessEngineFactoryImpl implements ManagedProcessEngineFactory { @Override public void updated(String pid, Dictionary properties) throws ConfigurationException { if (existingEngines.containsKey(pid)) { existingEngines.get(pid).close(); existingEngines.remove(pid); existingRegisteredEngines.get(pid).unregister(); existingRegisteredEngines.remove(pid); } if (!hasPropertiesConfiguration(properties)) { return; } ClassLoader previous = Thread.currentThread().getContextClassLoader(); ProcessEngine engine; try { ClassLoader cl = new BundleDelegatingClassLoader(bundle); Thread.currentThread().setContextClassLoader( new ClassLoaderWrapper(cl, ProcessEngineFactory.class.getClassLoader(), ProcessEngineConfiguration.class.getClassLoader(), previous)); ProcessEngineConfiguration processEngineConfiguration = createProcessEngineConfiguration(properties); processEngineConfiguration.setClassLoader(cl); engine = processEngineConfiguration.buildProcessEngine(); } finally { Thread.currentThread().setContextClassLoader(previous); } existingEngines.put(pid, engine); Hashtable<String, Object> props = new Hashtable<String, Object>(); props.put("process-engine-name", engine.getName()); ServiceRegistration<ProcessEngine> serviceRegistration = this.bundle.getBundleContext().registerService(ProcessEngine.class, engine, props); existingRegisteredEngines.put(pid, serviceRegistration); } ManagedProcessEngineFactoryImpl();  ManagedProcessEngineFactoryImpl(Bundle bundle); @Override String getName(); @Override void updated(String pid, Dictionary properties); @Override void deleted(String pid);  }### Answer:
@SuppressWarnings("unchecked") @Test public void updateEmptyConfiguration() throws ConfigurationException { Bundle bundle = mock(Bundle.class); BundleContext bundleContext = mock(BundleContext.class); when(bundle.getBundleContext()).thenReturn(bundleContext); ManagedProcessEngineFactoryImpl factory = new ManagedProcessEngineFactoryImpl(bundle); factory.updated("id", new Hashtable<String, String>()); verify(bundleContext, never()).registerService(eq(ProcessEngine.class), any(ProcessEngine.class), any(Dictionary.class)); }
@SuppressWarnings("unchecked") @Test public void updateConfigurationWithOnlyPidAndFactoryPid() throws ConfigurationException { Bundle bundle = mock(Bundle.class); BundleContext bundleContext = mock(BundleContext.class); when(bundle.getBundleContext()).thenReturn(bundleContext); ManagedProcessEngineFactoryImpl factory = new ManagedProcessEngineFactoryImpl(bundle); Hashtable<String, String> properties = new Hashtable<String, String>(); properties.put(Constants.SERVICE_PID, "id"); properties.put("service.factoryPid", "factory id"); factory.updated("id", properties); verify(bundleContext, never()).registerService(eq(ProcessEngine.class), any(ProcessEngine.class), any(Dictionary.class)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void updatedNewConfiguration() throws Exception { String engineName = "TestEngine"; Bundle bundle = mock(Bundle.class); mockGetResource(bundle); mockLoadClass(bundle); BundleContext bundleContext = mock(BundleContext.class); when(bundle.getBundleContext()).thenReturn(bundleContext); when(bundleContext.registerService(eq(ProcessEngine.class), any(ProcessEngine.class), any(Dictionary.class))).thenReturn(mock(ServiceRegistration.class)); ManagedProcessEngineFactoryImpl factory = new ManagedProcessEngineFactoryImpl(bundle); Hashtable<String, String> properties = createEngineProperties(engineName); factory.updated("id", properties); ArgumentCaptor<Dictionary> propsCapture = ArgumentCaptor.forClass(Dictionary.class); ArgumentCaptor<ProcessEngine> engineCapture = ArgumentCaptor.forClass(ProcessEngine.class); verify(bundleContext, times(1)).registerService(eq(ProcessEngine.class), engineCapture.capture(), propsCapture.capture()); assertThat(engineCapture.getValue(), is(notNullValue())); assertThat(propsCapture.getValue().get("process-engine-name"), is((Object) engineName)); assertThat(ProcessEngines.getProcessEngine(engineName), is(notNullValue())); }