### Question:
CriteriaSelectionStrategy implements SelectionStrategy { @Override public TopRewritingActionCollector createTopRewritingActionCollector() { final int count = limit.getCount(); if (count < 1 || !limit.isUseLevels()) { return new FlatTopRewritingActionCollector(sorting.getComparators(), count, filters); } else { return new TopLevelRewritingActionCollector(sorting.getComparators(), count, filters); } } CriteriaSelectionStrategy(final Criteria criteria); @Override TopRewritingActionCollector createTopRewritingActionCollector(); Sorting getSorting(); Limit getLimit(); List<FilterCriterion> getFilters();  }### Answer:
@Test public void testThatFlatCollectorIsUsedIfThereIsNotMaxCount() { final CriteriaSelectionStrategy strategy = new CriteriaSelectionStrategy(new Criteria(new PropertySorting("f1", Sorting.SortOrder.ASC), new Limit(-1, true), Collections.emptyList())); final TopRewritingActionCollector topRewritingActionCollector = strategy.createTopRewritingActionCollector(); assertTrue(topRewritingActionCollector instanceof FlatTopRewritingActionCollector); }
@Test public void testThatFlatCollectorIsUsedIfCountIsZero() { final CriteriaSelectionStrategy strategy = new CriteriaSelectionStrategy(new Criteria(new PropertySorting("f1", Sorting.SortOrder.ASC), new Limit(0, true), Collections.emptyList())); final TopRewritingActionCollector topRewritingActionCollector = strategy.createTopRewritingActionCollector(); assertTrue(topRewritingActionCollector instanceof FlatTopRewritingActionCollector); }
@Test public void testThatFlatCollectorIsUsedIfLevelsNotSetInLimit() { final CriteriaSelectionStrategy strategy = new CriteriaSelectionStrategy(new Criteria(new PropertySorting("f1", Sorting.SortOrder.ASC), new Limit(1, false), Collections.emptyList())); final TopRewritingActionCollector topRewritingActionCollector = strategy.createTopRewritingActionCollector(); assertTrue(topRewritingActionCollector instanceof FlatTopRewritingActionCollector); }
@Test public void testThatLevelCollectorIsUsedIfLevelsSetInLimit() { final CriteriaSelectionStrategy strategy = new CriteriaSelectionStrategy(new Criteria(new PropertySorting("f1", Sorting.SortOrder.ASC), new Limit(1, true), Collections.emptyList())); final TopRewritingActionCollector topRewritingActionCollector = strategy.createTopRewritingActionCollector(); assertTrue(topRewritingActionCollector instanceof TopLevelRewritingActionCollector); }