InstrumentationUtils { public static void instrument(String id, Object... args) { try { for (Listener l : listeners) { l.run(id, args); } } catch (Throwable t) { throw new RuntimeException(t); } } private  InstrumentationUtils(); static void instrument(String id, Object... args); static void addListener(Listener l); static void clear();  }
@Test public void testInstrument() { AtomicInteger i = new AtomicInteger(); InstrumentationUtils.addListener((String id, Object... args) -> { if (id.equals("one") && args.length == 1 && args[0].equals("two")) { i.incrementAndGet(); } }); InstrumentationUtils.instrument("one", "two"); assertEquals(1, i.get()); InstrumentationUtils.instrument("one", "three"); assertEquals(1, i.get()); InstrumentationUtils.instrument("one", "two"); assertEquals(2, i.get()); InstrumentationUtils.clear(); InstrumentationUtils.instrument("one", "two"); assertEquals(2, i.get()); }