ConsumerMetrics implements Metrics { double sum(List<Metric> metrics) { double sum = 0.0; for (var metric : metrics) { double value = (double) metric.metricValue(); if (Double.isFinite(value)) sum += value; } return sum; } ConsumerMetrics(String name); @Override void collect(Stats stats);  }
@Test void sum() { var metric1 = mock(Metric.class); when(metric1.metricValue()).thenReturn(1d); var metric2 = mock(Metric.class); when(metric2.metricValue()).thenReturn(Double.NEGATIVE_INFINITY); var metrics = new ConsumerMetrics(null); assertThat(metrics.sum(List.of(metric1, metric1, metric2))).isEqualTo(2); }