ConfigAdmin implements ConfigAdminMXBean { @Override public void configAdminUpdate(String pid, Map<String, String> data) { ServiceReference sref = bundleContext.getServiceReference(ConfigurationAdmin.class.getName()); if (sref == null) { throw new IllegalStateException("The configuration admin service cannot be found."); } try { ConfigurationAdmin ca = (ConfigurationAdmin) bundleContext.getService(sref); if (ca == null) { throw new IllegalStateException("The configuration admin service cannot be found."); } Configuration config = ca.getConfiguration(pid, null); config.update(new Hashtable<String, String>(data)); } catch (IOException ioe) { throw new RuntimeException(ioe); } finally { bundleContext.ungetService(sref); } } ConfigAdmin(BundleContext bc); @Override void configAdminUpdate(String pid, Map<String, String> data);  }
@Test @SuppressWarnings("unchecked") public void testConfigAdminUpdate() throws Exception { Configuration conf = Mockito.mock(Configuration.class); ConfigurationAdmin cas = Mockito.mock(ConfigurationAdmin.class); Mockito.when(cas.getConfiguration("mypid", null)).thenReturn(conf); ServiceReference sr = Mockito.mock(ServiceReference.class); BundleContext bc = Mockito.mock(BundleContext.class); Mockito.when(bc.getServiceReference(ConfigurationAdmin.class.getName())).thenReturn(sr); Mockito.when(bc.getService(sr)).thenReturn(cas); ConfigAdmin ca = new ConfigAdmin(bc); Map<String, String> props = new HashMap<>(); props.put("A", "B"); props.put("C D", "E F"); ca.configAdminUpdate("mypid", props); Mockito.verify(cas).getConfiguration("mypid", null); Mockito.verify(conf).update(new Hashtable<>(props)); }