@Override
  public List<PurgeableAnalysisDto> filter(List<PurgeableAnalysisDto> history) {
    List<Interval> intervals = Interval.group(history, start, end, dateField);
    List<PurgeableAnalysisDto> result = new ArrayList<>();
    for (Interval interval : intervals) {
      appendSnapshotsToDelete(interval, result);
    }

    return result;
  }
@Test
  void shouldOnlyOneSnapshotPerInterval() {
    Filter filter = new KeepOneFilter(DateUtils.parseDate("2011-03-25"), DateUtils.parseDate("2011-08-25"), Calendar.MONTH, "month");

    List<PurgeableAnalysisDto> toDelete = filter.filter(Arrays.asList(
      DbCleanerTestUtils.createAnalysisWithDate("u1", "2010-01-01"), // out of scope -> keep
      DbCleanerTestUtils.createAnalysisWithDate("u2", "2011-05-01"), // may -> keep
      DbCleanerTestUtils.createAnalysisWithDate("u3", "2011-05-02"), // may -> to be deleted
      DbCleanerTestUtils.createAnalysisWithDate("u4", "2011-05-19"), // may -> to be deleted
      DbCleanerTestUtils.createAnalysisWithDate("u5", "2011-06-01"), // june -> keep
      DbCleanerTestUtils.createAnalysisWithDate("u6", "2012-01-01") // out of scope -> keep
    ));

    assertThat(toDelete).hasSize(2);

    assertThat(analysisUuids(toDelete)).containsOnly("u2", "u3");
  }