StatisticsMonitor { public void addListener(final StatisticsListener listener) { if (listener == null) { throw new NullPointerException("StatisticsListener is null"); } synchronized (this.mutex) { if (!this.listeners.contains(listener)) { this.listeners.add(listener); getStatMonitorHandler().addMonitor(this); } } } StatisticsMonitor(); StatisticsMonitor addStatistic(final StatisticId statId); StatisticsMonitor removeStatistic(final StatisticId statId); void addListener(final StatisticsListener listener); void removeListener(final StatisticsListener listener); @Override String toString();  }
@Test public void testAddListener() { TestStatisticsMonitor monitor = new TestStatisticsMonitor(); assertTrue(monitor.getStatisticsListenersSnapshot().isEmpty()); StatisticsListener listener = new StatisticsListener() { @Override public void handleNotification(StatisticsNotification notification) {} }; assertNull(this.sampleCollector.getStatMonitorHandlerSnapshot()); monitor.addListener(listener); assertFalse(monitor.getStatisticsListenersSnapshot().isEmpty()); assertTrue(monitor.getStatisticsListenersSnapshot().contains(listener)); assertEquals(1, monitor.getStatisticsListenersSnapshot().size()); assertNotNull(this.sampleCollector.getStatMonitorHandlerSnapshot()); assertFalse( this.sampleCollector.getStatMonitorHandlerSnapshot().getMonitorsSnapshot().isEmpty()); }