### Question:
MetricCollectors { static Map<String, TopicSensors.Stat> getAggregateMetrics( final List<TopicSensors.Stat> allStats ) { Map<String, TopicSensors.Stat> results = new TreeMap<>(); allStats.forEach(stat -> { results.computeIfAbsent( stat.name(), k -> new TopicSensors.Stat(stat.name(), 0, stat.getTimestamp()) ); results.get(stat.name()).aggregate(stat.getValue()); }); return results; }  static void initialize(); static void cleanUp(); static String getStatsFor(final String topic, boolean isError); static void recordError(String topic); static Collection<Double> currentConsumptionRateByQuery(); static double currentProductionRate(); static double currentConsumptionRate(); static double totalMessageConsumption(); static double totalBytesConsumption(); static double currentErrorRate(); static Metrics getMetrics(); static Time getTime();  }### Answer:
@Test public void shouldAggregateStats() throws Exception { List<TopicSensors.Stat> stats = Arrays.asList(new TopicSensors.Stat("metric", 1, 1l), new TopicSensors.Stat("metric", 1, 1l), new TopicSensors.Stat("metric", 1, 1l)); Map<String, TopicSensors.Stat> aggregateMetrics = MetricCollectors.getAggregateMetrics(stats); assertThat(aggregateMetrics.size(), equalTo(1)); assertThat(aggregateMetrics.values().iterator().next().getValue(), equalTo(3.0)); }