TimedInterface { private TimedInterface() { } private  TimedInterface(); @SuppressWarnings("unchecked") static T newProxy(Class<T> ctype, T concrete, String id); static T newProxy(Class<T> ctype, T concrete);  }
@SuppressWarnings("unchecked") @Test public void testTimedInterface() { final IDummy dummy = TimedInterface.newProxy(IDummy.class, new DummyImpl(), "id"); final CompositeMonitor<Long> compositeMonitor = (CompositeMonitor<Long>) dummy; final List<Monitor<?>> monitors = compositeMonitor.getMonitors(); assertEquals(monitors.size(), 3); assertEquals(compositeMonitor.getValue().longValue(), 3L); DefaultMonitorRegistry.getInstance().register((CompositeMonitor) dummy); for (int i = 0; i < 42; i++) { dummy.method1(); if (i % 2 == 0) { dummy.method2(i); } } final TagList tagList = BasicTagList.of( TimedInterface.CLASS_TAG, "DummyImpl", TimedInterface.INTERFACE_TAG, "IDummy", TimedInterface.ID_TAG, "id"); final MonitorConfig expectedConfig = MonitorConfig.builder(TimedInterface.TIMED_INTERFACE) .withTags(tagList).build(); assertEquals(compositeMonitor.getConfig(), expectedConfig); for (Monitor<?> monitor : monitors) { final MonitorConfig config = monitor.getConfig(); final String method = config.getName(); final MonitorConfig expected = MonitorConfig.builder(method).withTags(tagList).build(); assertEquals(config, expected); switch (method) { case "method1": { long value = ((Monitor<Long>) monitor).getValue() - 20; assertTrue(value >= 0 && value <= 9); break; } case "method2": { long value = ((Monitor<Long>) monitor).getValue() - 40; assertTrue(value >= 0 && value <= 9); break; } default: { assertEquals(method, "method3"); long value = ((Monitor<Long>) monitor).getValue(); assertEquals(value, 0); break; } } } }