### Question:
MetricCollectors { public static String getStatsFor(final String topic, boolean isError) { ArrayList<TopicSensors.Stat> allStats = new ArrayList<>(); collectorMap.values().forEach(c -> allStats.addAll(c.stats(topic.toLowerCase(), isError))); Map<String, TopicSensors.Stat> aggregateStats = getAggregateMetrics(allStats); return format(aggregateStats.values(), isError ? "last-failed" : "last-message"); }  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 shouldKeepWorkingWhenDuplicateTopicConsumerIsRemoved() throws Exception { ConsumerCollector collector1 = new ConsumerCollector(); collector1.configure(ImmutableMap.of(ConsumerConfig.GROUP_ID_CONFIG, "stream-thread-1") ); ConsumerCollector collector2 = new ConsumerCollector(); collector2.configure(ImmutableMap.of(ConsumerConfig.GROUP_ID_CONFIG, "stream-thread-2") ); Map<TopicPartition, List<ConsumerRecord<Object, Object>>> records = ImmutableMap.of( new TopicPartition(TEST_TOPIC, 1), Arrays.asList( new ConsumerRecord<>(TEST_TOPIC, 1, 1, 1l, TimestampType.CREATE_TIME, 1l, 10, 10, "key", "1234567890")) ); ConsumerRecords<Object, Object> consumerRecords = new ConsumerRecords<>(records); collector1.onConsume(consumerRecords); collector2.onConsume(consumerRecords); String firstPassStats = MetricCollectors.getStatsFor(TEST_TOPIC, false); assertTrue("Missed stats, got:" + firstPassStats, firstPassStats.contains("total-messages: 2")); collector2.close(); collector1.onConsume(consumerRecords); String statsForTopic2 = MetricCollectors.getStatsFor(TEST_TOPIC, false); assertTrue("Missed stats, got:" + statsForTopic2, statsForTopic2.contains("total-messages: 2")); }