StatisticsRegistry implements StatisticsManager { @Override public Statistics[] findStatisticsByType(StatisticsType type) { return allStatisticsInstances(withStatisticsType(type)) .toArray(Statistics[]::new); } StatisticsRegistry(String name, long startTime);   StatisticsRegistry(String name, long startTime, StatisticsTypeFactory typeFactory,
      OsStatisticsFactory osStatisticsFactory, AtomicStatisticsFactory atomicStatisticsFactory,
      IntSupplier pidSupplier); @Override String getName(); @Override int getPid(); @Override long getStartTime(); @Override List<Statistics> getStatsList(); @Override int getStatListModCount(); @Override Statistics[] getStatistics(); @Override int getStatisticsCount(); @Override StatisticsType createType(String name, String description, StatisticDescriptor[] stats); @Override StatisticsType[] createTypesFromXml(Reader reader); @Override StatisticsType findType(String name); @Override Statistics createStatistics(StatisticsType type); @Override Statistics createAtomicStatistics(StatisticsType type); @Override Statistics createStatistics(StatisticsType type, String textId); @Override Statistics createAtomicStatistics(StatisticsType type, String textId); @Override Statistics createStatistics(StatisticsType type, String textId, long numericId); @Override Statistics createAtomicStatistics(StatisticsType type, String textId, long numericId); @Override Statistics createOsStatistics(StatisticsType type, String textId, long numericId,
      int osStatFlags); @Override void destroyStatistics(Statistics statisticsToDestroy); @Override boolean statisticsExists(long uniqueId); @Override Statistics findStatisticsByUniqueId(long uniqueId); @Override Statistics[] findStatisticsByNumericId(long numericId); @Override Statistics[] findStatisticsByTextId(String textId); @Override Statistics[] findStatisticsByType(StatisticsType type); @Override StatisticDescriptor createIntCounter(String name, String description, String units); @Override StatisticDescriptor createLongCounter(String name, String description, String units); @Override StatisticDescriptor createDoubleCounter(String name, String description, String units); @Override StatisticDescriptor createIntGauge(String name, String description, String units); @Override StatisticDescriptor createLongGauge(String name, String description, String units); @Override StatisticDescriptor createDoubleGauge(String name, String description, String units); @Override StatisticDescriptor createIntCounter(String name, String description, String units,
      boolean largerBetter); @Override StatisticDescriptor createLongCounter(String name, String description, String units,
      boolean largerBetter); @Override StatisticDescriptor createDoubleCounter(String name, String description, String units,
      boolean largerBetter); @Override StatisticDescriptor createIntGauge(String name, String description, String units,
      boolean largerBetter); @Override StatisticDescriptor createLongGauge(String name, String description, String units,
      boolean largerBetter); @Override StatisticDescriptor createDoubleGauge(String name, String description, String units,
      boolean largerBetter);  }
@Test public void findStatisticsByType_returnsAllStatisticsThatMatchType() { StatisticsType soughtType = mock(StatisticsType.class, "matching type"); StatisticsType differentType = mock(StatisticsType.class, "mismatching type"); Statistics matchingStatistics1 = statistics(withType(soughtType)); Statistics matchingStatistics2 = statistics(withType(soughtType)); Statistics mismatchingStatistics = statistics(withType(differentType)); givenExistingStatistics( matchingStatistics2, matchingStatistics1, mismatchingStatistics); Statistics[] foundStatistics = registry.findStatisticsByType(soughtType); assertThat(foundStatistics) .containsExactlyInAnyOrder( matchingStatistics1, matchingStatistics2); }
@Test public void findStatisticsByType_returnsEmptyArray_ifNoStatisticsMatchType() { StatisticsType soughtType = mock(StatisticsType.class, "matching type"); StatisticsType differentType = mock(StatisticsType.class, "mismatching type"); givenExistingStatistics( statistics(withType(differentType)), statistics(withType(differentType)), statistics(withType(differentType))); assertThat(registry.findStatisticsByType(soughtType)).isEmpty(); }