DistributionProviderTracker extends ServiceTracker<DistributionProvider, ServiceRegistration> { @Override public ServiceRegistration addingService(ServiceReference<DistributionProvider> reference) { DistributionProvider provider = context.getService(reference); if (provider == null) { return null; } LOG.debug("RemoteServiceAdmin Implementation is starting up"); BundleContext apiContext = getAPIContext(); PackageUtil packageUtil = new PackageUtil(context); EventProducer eventProducer = new EventProducer(context); RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(context, apiContext, eventProducer, provider, packageUtil); RemoteServiceAdminFactory rsaf = new RemoteServiceAdminFactory(rsaCore); Dictionary<String, Object> props = new Hashtable<>(); props.put(REMOTE_INTENTS_SUPPORTED, getPropertyNullSafe(reference, REMOTE_INTENTS_SUPPORTED)); props.put(REMOTE_CONFIGS_SUPPORTED, getPropertyNullSafe(reference, REMOTE_CONFIGS_SUPPORTED)); LOG.info("Registering RemoteServiceAdmin for provider " + provider.getClass().getName()); return context.registerService(RemoteServiceAdmin.class.getName(), rsaf, props); } DistributionProviderTracker(BundleContext context); @Override ServiceRegistration addingService(ServiceReference<DistributionProvider> reference); @Override void removedService(ServiceReference<DistributionProvider> reference,
                               ServiceRegistration reg);  }
@Test public void testAddingWithNullValues() throws InvalidSyntaxException { IMocksControl c = EasyMock.createControl(); DistributionProvider provider = c.createMock(DistributionProvider.class); ServiceReference<DistributionProvider> providerRef = c.createMock(ServiceReference.class); expect(providerRef.getProperty(RemoteConstants.REMOTE_INTENTS_SUPPORTED)).andReturn(null); expect(providerRef.getProperty(RemoteConstants.REMOTE_CONFIGS_SUPPORTED)).andReturn(null); BundleContext context = c.createMock(BundleContext.class); String filterSt = String.format("(objectClass=%s)", DistributionProvider.class.getName()); Filter filter = FrameworkUtil.createFilter(filterSt); expect(context.createFilter(filterSt)).andReturn(filter); expect(context.getService(providerRef)).andReturn(provider); ServiceRegistration rsaReg = c.createMock(ServiceRegistration.class); expect(context.registerService(EasyMock.isA(String.class), EasyMock.isA(ServiceFactory.class), EasyMock.isA(Dictionary.class))) .andReturn(rsaReg).atLeastOnce(); context.addServiceListener(anyObject(ServiceListener.class)); expectLastCall().anyTimes(); final BundleContext apiContext = c.createMock(BundleContext.class); c.replay(); DistributionProviderTracker tracker = new DistributionProviderTracker(context) { protected BundleContext getAPIContext() { return apiContext; } }; tracker.addingService(providerRef); c.verify(); }