### Question:
ConnectionFactoryRegistration implements Closeable { @Override public void close() { if (serviceReg != null) { serviceReg.unregister(); } safeClose(connectionFactory); } ConnectionFactoryRegistration(BundleContext context, ConnectionFactoryFactory cff, final Dictionary<String, Object> config, final Dictionary<String, Object> decryptedConfig); @Override void close();  }### Answer:
@Test public void testPublishedAndUnpublished() throws ConfigurationException, InvalidSyntaxException, SQLException { Capture<Map<String, Object>> capturedCfProps = EasyMock.newCapture(); Capture<Dictionary> capturedServiceProps = EasyMock.newCapture(); IMocksControl c = EasyMock.createControl(); BundleContext context = c.createMock(BundleContext.class); final ConnectionFactoryFactory cff = c.createMock(ConnectionFactoryFactory.class); ConnectionFactory cf = c.createMock(ConnectionFactory.class); expect(cff.createConnectionFactory(capture(capturedCfProps))).andReturn(cf); ServiceRegistration cfSreg = c.createMock(ServiceRegistration.class); expect( context.registerService(eq(ConnectionFactory.class.getName()), eq(cf), capture(capturedServiceProps))).andReturn(cfSreg); c.replay(); Dictionary<String, Object> properties = new Hashtable(); properties.put(ConnectionFactoryFactory.JMS_CONNECTIONFACTORY_NAME, "mycfname"); ConnectionFactoryRegistration publisher = new ConnectionFactoryRegistration(context, cff, properties, properties); c.verify(); Dictionary serviceProps = capturedServiceProps.getValue(); assertEquals("mycfname", serviceProps.get(ConnectionFactoryFactory.JMS_CONNECTIONFACTORY_NAME)); assertEquals("mycfname", serviceProps.get("osgi.jndi.service.name")); c.reset(); cfSreg.unregister(); expectLastCall(); c.replay(); publisher.close(); c.verify(); }