@Test public void testFindWatch() { WatchDataSourceRegistry registry = new WatchDataSourceRegistry(); int[] counts = new int[] {0, 1, 10, 100}; for (int count : counts) { Collection<Watch> watches = new ArrayList<Watch>(); for (int k = 0; k < count; k++) { String id = "watch" + k; if (k == 1) { id = ""; } WatchDataSource ds = new WatchDataSourceImpl( id, EmptyConfiguration.INSTANCE); watches.add(new GaugeWatch(ds, id)); } for (int j = 0; j < 5; j++) { for (Watch watch : watches) { String id = watch.getId(); Watch res = registry.findWatch(id); Assert.assertNull(res); } for (Watch watch : watches) { registry.register(watch); } for (Watch watch : watches) { String id = watch.getId(); Watch res = registry.findWatch(id); Assert.assertNotNull(res); Assert.assertSame(watch, res); } Assert.assertNull(registry.findWatch("aaa")); for (Watch watch : watches) { registry.deregister(watch); } for (Watch watch : watches) { String id = watch.getId(); Watch res = registry.findWatch(id); Assert.assertNull(res); } } } try { registry.findWatch(null); Assert.fail("IllegalArgumentException expected but not thrown"); } catch (IllegalArgumentException e) { } }
public Watch findWatch(String id) { if(id == null) throw new IllegalArgumentException("id is null"); Watch watch = null; for(Watch w : watchRegistry) { if(id.equals(w.getId())) { watch = w; break; } } return watch; }
WatchDataSourceRegistry implements WatchRegistry { public Watch findWatch(String id) { if(id == null) throw new IllegalArgumentException("id is null"); Watch watch = null; for(Watch w : watchRegistry) { if(id.equals(w.getId())) { watch = w; break; } } return watch; } }
WatchDataSourceRegistry implements WatchRegistry { public Watch findWatch(String id) { if(id == null) throw new IllegalArgumentException("id is null"); Watch watch = null; for(Watch w : watchRegistry) { if(id.equals(w.getId())) { watch = w; break; } } return watch; }  }
WatchDataSourceRegistry implements WatchRegistry { public Watch findWatch(String id) { if(id == null) throw new IllegalArgumentException("id is null"); Watch watch = null; for(Watch w : watchRegistry) { if(id.equals(w.getId())) { watch = w; break; } } return 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); }
WatchDataSourceRegistry implements WatchRegistry { public Watch findWatch(String id) { if(id == null) throw new IllegalArgumentException("id is null"); Watch watch = null; for(Watch w : watchRegistry) { if(id.equals(w.getId())) { watch = w; break; } } return 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);  }