ObserverTracker implements ServiceTrackerCustomizer { @Override public void removedService(ServiceReference reference, Object service) { Closeable subscription = subscriptions.remove(reference); if (subscription != null) { closeQuietly(subscription); bundleContext.ungetService(reference); } } 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 unregisterWhenEmpty() { tracker.removedService(ref1, null); assertTrue(observers.isEmpty()); }