PluginableElementsContainer { public void addElement(T element) { boolean allreadyHave = false; synchronized (elements) { allreadyHave = elements.containsKey(element.getPluginableId()); elements.put(element.getPluginableId(), element); } synchronized (listeners) { if (allreadyHave) { notifyChange(element); } else { notifyAdd(element); } } } PluginableElementsContainer();  PluginableElementsContainer(Collection<T> e); Collection<T> getElements(); T getElement(String pluginableId); boolean contains(T element); void addElement(T element); void addListener(PluginableElementEventListener<T> listener); void removeListener(PluginableElementEventListener<T> listener); void removeElement(T element); void changeElement(T element);  }
@Test public void testAddElement() { PluginableListener listener = new PluginableListener(); container.addListener(listener); PluginableClass p1 = new PluginableClass(); container.addElement(p1); AssertJUnit.assertTrue(listener.added); container.addElement(p1); AssertJUnit.assertTrue(listener.changed); Collection<PluginableClass> elements = container.getElements(); AssertJUnit.assertEquals(1, elements.size()); }