MBeanStatsMonitor implements StatisticsListener { public void addStatisticsToMonitor(final Statistics stats) { monitor.addListener(this); StatisticsType type = stats.getType(); StatisticDescriptor[] descriptors = type.getStatistics(); for (StatisticDescriptor d : descriptors) { statsMap.put(d.getName(), stats.get(d)); } monitor.addStatistics(stats); } MBeanStatsMonitor(final String name);   MBeanStatsMonitor(final String name, final ValueMonitor monitor); void addStatisticsToMonitor(final Statistics stats); void removeStatisticsFromMonitor(final Statistics stats); void stopListener(); Number getStatistic(final String statName); @Override void handleNotification(final StatisticsNotification notification);  }
@Test public void addStatisticsToMonitorShouldAddToInternalMap() { this.mbeanStatsMonitor.addStatisticsToMonitor(this.stats); assertThat(mbeanStatsMonitor.statsMap).containsAllEntriesOf(this.expectedStatsMap); }
@Test public void addStatisticsToMonitorShouldAddListener() { this.mbeanStatsMonitor.addStatisticsToMonitor(this.stats); verify(this.statsMonitor, times(1)).addListener(this.mbeanStatsMonitor); }
@Test public void addStatisticsToMonitorShouldAddStatistics() { this.mbeanStatsMonitor.addStatisticsToMonitor(this.stats); verify(this.statsMonitor, times(1)).addStatistics(this.stats); }
@Test public void addNullStatisticsToMonitorShouldThrowNPE() { assertThatThrownBy(() -> this.mbeanStatsMonitor.addStatisticsToMonitor(null)) .isExactlyInstanceOf(NullPointerException.class); }