AggregationUnitFactory { public static AggregationUnit create(final AggregationType type, final boolean isDistinct) { switch (type) { case MAX: return new ComparableAggregationUnit(false); case MIN: return new ComparableAggregationUnit(true); case SUM: return isDistinct ? new DistinctSumAggregationUnit() : new AccumulationAggregationUnit(); case COUNT: return isDistinct ? new DistinctCountAggregationUnit() : new AccumulationAggregationUnit(); case AVG: return isDistinct ? new DistinctAverageAggregationUnit() : new AverageAggregationUnit(); default: throw new UnsupportedOperationException(type.name()); } }  static AggregationUnit create(final AggregationType type, final boolean isDistinct);  }
@Test public void assertCreateComparableAggregationUnit() { assertThat(AggregationUnitFactory.create(AggregationType.MIN, false), instanceOf(ComparableAggregationUnit.class)); assertThat(AggregationUnitFactory.create(AggregationType.MAX, false), instanceOf(ComparableAggregationUnit.class)); }
@Test public void assertCreateAccumulationAggregationUnit() { assertThat(AggregationUnitFactory.create(AggregationType.SUM, false), instanceOf(AccumulationAggregationUnit.class)); assertThat(AggregationUnitFactory.create(AggregationType.COUNT, false), instanceOf(AccumulationAggregationUnit.class)); }
@Test public void assertCreateAverageAggregationUnit() { assertThat(AggregationUnitFactory.create(AggregationType.AVG, false), instanceOf(AverageAggregationUnit.class)); }
@Test public void assertCreateDistinctSumAggregationUnit() { assertThat(AggregationUnitFactory.create(AggregationType.SUM, true), instanceOf(DistinctSumAggregationUnit.class)); }
@Test public void assertCreateDistinctCountAggregationUnit() { assertThat(AggregationUnitFactory.create(AggregationType.COUNT, true), instanceOf(DistinctCountAggregationUnit.class)); }
@Test public void assertCreateDistinctAverageAggregationUnit() { assertThat(AggregationUnitFactory.create(AggregationType.AVG, true), instanceOf(DistinctAverageAggregationUnit.class)); }