Monitors { public static CompositeMonitor<?> newObjectMonitor(Object obj) { return newObjectMonitor(null, obj); } private  Monitors(); static Timer newTimer(String name); static Timer newTimer(String name, TaggingContext context); static Timer newTimer(String name, TimeUnit unit); static Timer newTimer(String name, TimeUnit unit, TaggingContext context); static Counter newCounter(String name); static Counter newCounter(String name, TaggingContext context); static CompositeMonitor<?> newObjectMonitor(Object obj); static CompositeMonitor<?> newObjectMonitor(String id, Object obj); static CompositeMonitor<?> newThreadPoolMonitor(String id, ThreadPoolExecutor pool); static CompositeMonitor<?> newCacheMonitor(String id, Cache<?, ?> cache); static void registerObject(Object obj); static void unregisterObject(Object obj); static void unregisterObject(String id, Object obj); static void registerObject(String id, Object obj); static boolean isObjectRegistered(Object obj); static boolean isObjectRegistered(String id, Object obj);  }
@Test public void testNewObjectMonitor() throws Exception { ClassWithMonitors obj = new ClassWithMonitors(); List<Monitor<?>> monitors = Monitors.newObjectMonitor(obj).getMonitors(); assertEquals(monitors.size(), 8); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNewObjectMonitorWithBadAnnotation() throws Exception { ClassWithBadAnnotation obj = new ClassWithBadAnnotation(); Monitors.newObjectMonitor(obj); }
@Test public void testNewObjectMonitorWithParentClass() throws Exception { ParentHasMonitors obj = new ParentHasMonitors(); List<Monitor<?>> monitors = Monitors.newObjectMonitor(obj).getMonitors(); for (Monitor m : monitors) { assertEquals(m.getConfig().getTags().getValue("class"), "ParentHasMonitors", String.format("%s should have class ParentHasMonitors", m.getConfig().getName())); } assertEquals(monitors.size(), 10); }
@Test public void testAddMonitorsAnnoHierarchical() throws Exception { SuperClassWithMonitors.ChildClassWithMonitors obj = new SuperClassWithMonitors.ChildClassWithMonitors(); CompositeMonitor compositeMonitor = Monitors.newObjectMonitor(obj); @SuppressWarnings("unchecked") List<Monitor> monitors = compositeMonitor.getMonitors(); assertEquals(monitors.size(), 4); for(Monitor m : monitors) { String tagValue = m.getConfig().getTags().asMap().get("tag1"); assertNotNull(tagValue, "tag value not returned"); assertEquals(tagValue, "tag2", "tag value is not tag2"); } }