MetricObserverUtil { public static boolean addMetricObservers(Registry registry, MetricObserver... metricObservers) { boolean flag = false; if (registry instanceof LookoutRegistry) { for (MetricObserver metricObserver : metricObservers) { ((LookoutRegistry) registry).addMetricObserver(metricObserver); } flag = true; } if (registry instanceof CompositeRegistry) { for (Registry reg : ((CompositeRegistry) registry).getRegistries()) { if (reg instanceof LookoutRegistry) { for (MetricObserver metricObserver : metricObservers) { ((LookoutRegistry) reg).addMetricObserver(metricObserver); } flag = true; } } } return flag; } private  MetricObserverUtil(); static boolean addMetricObservers(Registry registry, MetricObserver... metricObservers);  }
@Test public void testAddMetricObserver() { LookoutRegistry reg = new LookoutRegistry(new LookoutConfig()); LogObserver logObserver = new LogObserver(); MetricObserverUtil.addMetricObservers(reg, logObserver); Assert.assertTrue(reg.getMetricObservers().contains(logObserver)); }
@Test public void testAddMetricObserverWithCompositeRegistry() { LookoutRegistry reg = new LookoutRegistry(new LookoutConfig()); LogObserver logObserver = new LogObserver(); CompositeRegistry compositeRegistry = new CompositeRegistry(Clock.SYSTEM); compositeRegistry.add(reg); MetricObserverUtil.addMetricObservers(compositeRegistry, logObserver); Assert.assertTrue(reg.getMetricObservers().contains(logObserver)); }