ObserverTracker implements ServiceTrackerCustomizer { @Override public Object addingService(ServiceReference reference) { Object service = bundleContext.getService(reference); if (service instanceof Observer) { subscriptions.put(reference, observable.addObserver((Observer) service)); return service; } else { bundleContext.ungetService(reference); return null; } } ObserverTracker(@NotNull Observable observable); void start(@NotNull BundleContext bundleContext); void stop(); @Override Object addingService(ServiceReference reference); @Override void modifiedService(ServiceReference reference, Object service); @Override void removedService(ServiceReference reference, Object service);  }
@Test public void registerTwice() { tracker.addingService(ref1); assertEquals(ImmutableSet.of(observer1), observers); tracker.addingService(ref1); assertEquals(ImmutableSet.of(observer1), observers); }