LocalDiscovery implements BundleListener { void unbindListener(EndpointEventListener endpointListener) { synchronized (listenerToFilters) { Collection<String> filters = listenerToFilters.remove(endpointListener); if (filters == null) { return; } for (String filter : filters) { Collection<EndpointEventListener> listeners = filterToListeners.get(filter); if (listeners != null) { listeners.remove(endpointListener); if (listeners.isEmpty()) { filterToListeners.remove(filter); } } } } } LocalDiscovery(); @Activate void activate(BundleContext context); @Deactivate void deactivate(BundleContext context); void processExistingBundles(Bundle[] bundles); void bundleChanged(BundleEvent be);  }
@Test public void testClearTracker() throws Exception { LocalDiscovery ld = new LocalDiscovery(); EndpointEventListener endpointListener = EasyMock.createMock(EndpointEventListener.class); ld.listenerToFilters.put(endpointListener, new ArrayList<>(Arrays.asList("(a=b)", "(objectClass=foo.bar.Bheuaark)"))); ld.filterToListeners.put("(a=b)", new ArrayList<>(Arrays.asList(endpointListener))); ld.filterToListeners.put("(objectClass=foo.bar.Bheuaark)", new ArrayList<>(Arrays.asList(endpointListener))); assertEquals(1, ld.listenerToFilters.size()); assertEquals(2, ld.filterToListeners.size()); assertEquals(1, ld.filterToListeners.values().iterator().next().size()); ld.unbindListener(EasyMock.createMock(EndpointEventListener.class)); assertEquals(1, ld.listenerToFilters.size()); assertEquals(2, ld.filterToListeners.size()); assertEquals(1, ld.filterToListeners.values().iterator().next().size()); ld.unbindListener(endpointListener); assertEquals(0, ld.listenerToFilters.size()); assertEquals(0, ld.filterToListeners.size()); }