### Question:
WatchDataSourceRegistry implements WatchRegistry { public void addThresholdListener(String id, ThresholdListener thresholdListener) { if(id==null) throw new IllegalArgumentException("id is null"); if(thresholdListener==null) throw new IllegalArgumentException("thresholdListener is null"); Collection<ThresholdListener> collection; if(thresholdListenerTable.containsKey(id)) { collection = thresholdListenerTable.get(id); } else { collection = new ArrayList<>(); } if(!collection.contains(thresholdListener)) { if(logger.isTraceEnabled()) logger.trace("Add [{}] for watch [{}]", thresholdListener.getClass().getName(), id); collection.add(thresholdListener); thresholdListenerTable.put(id, collection); Watch watch = findWatch(id); if(logger.isTraceEnabled()) logger.trace("Found [{}] previously registered watch [{}]", (watch==null?0:1), id); if(watch!=null) { associateThresholdListener(watch); } } }  void deregister(Watch... watches); void closeAll(); void register(Watch... watches); void addThresholdListener(String id, ThresholdListener thresholdListener); void removeThresholdListener(String id, ThresholdListener thresholdListener); Watch findWatch(String id); WatchDataSource[] fetch(); WatchDataSource fetch(String id); void setServiceBeanContext(ServiceBeanContext context);  }### Answer:
@Test public void testAddThresholdListener() { WatchDataSourceRegistry registry = new WatchDataSourceRegistry(); int[] watchCounts = new int[] {1, 5, 10}; int[] listenerCounts = new int[] {1, 5, 10}; for (int ordering = 0; ordering < 3; ordering++) { for (int watchCount : watchCounts) { for (int listenerCount : listenerCounts) { Map<Watch, WatchEntry> map = new HashMap<Watch, WatchEntry>(); check(map, ordering); setup(map, watchCount, listenerCount); populate(registry, map, ordering); check(map, ordering); clear(registry, map); check(new HashMap<Watch, WatchEntry>(), ordering); populate(registry, map, ordering); check(map, ordering); clear(registry, map); check(new HashMap<Watch, WatchEntry>(), ordering); } } } try { registry.addThresholdListener(null, new LoggingThresholdListener()); Assert.fail("IllegalArgumentException expected but not thrown"); } catch (IllegalArgumentException e) { } try { registry.addThresholdListener("aaa", null); Assert.fail("IllegalArgumentException expected but not thrown"); } catch (IllegalArgumentException e) { } }