AvgDistinct extends SumDistinct { @Override public Object terminate() { double sum = ((Number) super.terminate()).doubleValue(); double result = sum / this.distinct.size(); return downCast(result); }  @Override Object terminate();  }
@Test public void terminateShouldCorrectlyComputeAverageUponDistinctAccumulatedValues() { distinctAggregator.accumulate(5); distinctAggregator.accumulate(5); distinctAggregator.accumulate(10); distinctAggregator.accumulate(10); distinctAggregator.accumulate(15); distinctAggregator.accumulate(15); Object result = distinctAggregator.terminate(); assertThat(result).isInstanceOf(Number.class); assertThat(((Number) result).floatValue()).isEqualTo(10); }