GCStatsMonitor extends MBeanStatsMonitor { @Override public Number getStatistic(String statName) { if (statName.equals(StatsKey.VM_GC_STATS_COLLECTIONS)) { return getCollections(); } if (statName.equals(StatsKey.VM_GC_STATS_COLLECTION_TIME)) { return getCollectionTime(); } return 0; } GCStatsMonitor(String name); @VisibleForTesting  GCStatsMonitor(String name, ValueMonitor valueMonitor); @Override // this will be called multiple times initially with different collector's stats void addStatisticsToMonitor(Statistics stats); @Override Number getStatistic(String statName); @Override // this will be called each time a collector's stats changed void handleNotification(StatisticsNotification notification);  }
@Test public void getStatisticShouldReturnZeroForUnknownStatistics() { assertThat(gcStatsMonitor.getStatistic("unknownStatistic")).isEqualTo(0); }