MonitorableRegistry { public synchronized <T> void register(Monitorable<T> monitorable) { if (monitorables.containsKey(monitorable.getName())) { throw new UnsupportedOperationException( "There is already an instance of the Monitorable [" + monitorable.getName() + "] registered."); } monitorables.put(monitorable.getName(), monitorable); notifyListenersOfNewMonitorable(monitorable); }  synchronized void register(Monitorable<T> monitorable); @SuppressWarnings("unchecked") synchronized T registerOrReuse(Monitorable<T> monitorable); synchronized Collection<Monitorable<?>> getMonitorables(); static void clearDefaultRegistry(); static MonitorableRegistry getNamedInstance(String name); void addRegistryListener(MonitorableRegistryListener monitorableRegistryListener); void removeRegistryListener(MonitorableRegistryListener listener); static MonitorableRegistry DEFAULT_REGISTRY; }
@Test(expected = UnsupportedOperationException.class) public void registerWithDuplicateNameThrowsException() { MonitorableRegistry registry = newRegistry(); Monitorable<?> dummy = new DummyMonitorable("foo"); registry.register(dummy); Monitorable<?> dummy2 = new DummyMonitorable("foo"); registry.register(dummy2); }