EventProducer { public void publishNotification(List<ExportRegistration> erl) { for (ExportRegistration exportRegistration : erl) { publishNotification(exportRegistration); } } EventProducer(BundleContext bc); void publishNotification(List<ExportRegistration> erl); void publishNotification(ImportRegistration ir); void notifyRemoval(ExportReference er); void notifyRemoval(ImportRegistration ir); void notifyUpdate(ExportReference exportRef); void notifyUpdate(ImportRegistration importReg);  }
@Test public void testPublishNotification() throws Exception { final EndpointDescription epd = dummyEndpoint(); Endpoint endpoint = c.createMock(Endpoint.class); expect(endpoint.description()).andReturn(epd); final ServiceReference sref = c.createMock(ServiceReference.class); c.replay(); EventProducer eventProducer = new EventProducer(bc); ExportRegistrationImpl ereg = new ExportRegistrationImpl(sref, endpoint, closeHandler, eventProducer); eventProducer.publishNotification(ereg); RemoteServiceAdminEvent rsae = capturedEvent.getValue(); Assert.assertNull(rsae.getException()); Assert.assertEquals(RemoteServiceAdminEvent.EXPORT_REGISTRATION, rsae.getType()); Assert.assertSame(bundle, rsae.getSource()); ExportReference er = rsae.getExportReference(); Assert.assertSame(epd, er.getExportedEndpoint()); Assert.assertSame(sref, er.getExportedService()); c.verify(); }
@Test public void testPublishErrorNotification() throws Exception { c.replay(); EventProducer eventProducer = new EventProducer(bc); final Exception exportException = new Exception(); ExportRegistrationImpl ereg = new ExportRegistrationImpl(exportException, closeHandler, eventProducer); eventProducer.publishNotification(Arrays.asList(ereg)); RemoteServiceAdminEvent rsae = capturedEvent.getValue(); Assert.assertSame(exportException, rsae.getException()); Assert.assertEquals(RemoteServiceAdminEvent.EXPORT_ERROR, rsae.getType()); Assert.assertSame(bundle, rsae.getSource()); Assert.assertNull(rsae.getImportReference()); Assert.assertNull(rsae.getExportReference()); c.verify(); }