@Test public void findObsoleteTests() { Instant instant = clock.instant(); List<TestTime> tests = new ArrayList<>(); for(int i = 0; i < 10; ++i) { TestTime mock = mock(TestTime.class); doReturn(Timestamp.from(instant)).when(mock).getLastUpdated(); tests.add(mock); } Instant oldInstant = instant.minus(5, ChronoUnit.DAYS); testTimeLastUpdatedAt(oldInstant); tests.add(testTime); Set<TestTime> obsoleteTests = PersistenceUtil.findObsoleteTests(tests); assertEquals(1, obsoleteTests.size()); assertEquals(testTime, Iterables.getFirst(obsoleteTests, null)); }
static Set<TestTime> findObsoleteTests(Collection<TestTime> testTimes) { Optional<Instant> maybeAverage = calculateAverageLastUpdatedTime(testTimes); if(!maybeAverage.isPresent()) { return Collections.emptySet(); } Instant averageLastUpdated = maybeAverage.get(); return testTimes.stream() .filter(t -> isTestOlderThanAverage(averageLastUpdated, t)) .collect(Collectors.toSet()); }
PersistenceUtil { static Set<TestTime> findObsoleteTests(Collection<TestTime> testTimes) { Optional<Instant> maybeAverage = calculateAverageLastUpdatedTime(testTimes); if(!maybeAverage.isPresent()) { return Collections.emptySet(); } Instant averageLastUpdated = maybeAverage.get(); return testTimes.stream() .filter(t -> isTestOlderThanAverage(averageLastUpdated, t)) .collect(Collectors.toSet()); } }
PersistenceUtil { static Set<TestTime> findObsoleteTests(Collection<TestTime> testTimes) { Optional<Instant> maybeAverage = calculateAverageLastUpdatedTime(testTimes); if(!maybeAverage.isPresent()) { return Collections.emptySet(); } Instant averageLastUpdated = maybeAverage.get(); return testTimes.stream() .filter(t -> isTestOlderThanAverage(averageLastUpdated, t)) .collect(Collectors.toSet()); }  }
PersistenceUtil { static Set<TestTime> findObsoleteTests(Collection<TestTime> testTimes) { Optional<Instant> maybeAverage = calculateAverageLastUpdatedTime(testTimes); if(!maybeAverage.isPresent()) { return Collections.emptySet(); } Instant averageLastUpdated = maybeAverage.get(); return testTimes.stream() .filter(t -> isTestOlderThanAverage(averageLastUpdated, t)) .collect(Collectors.toSet()); }   }
PersistenceUtil { static Set<TestTime> findObsoleteTests(Collection<TestTime> testTimes) { Optional<Instant> maybeAverage = calculateAverageLastUpdatedTime(testTimes); if(!maybeAverage.isPresent()) { return Collections.emptySet(); } Instant averageLastUpdated = maybeAverage.get(); return testTimes.stream() .filter(t -> isTestOlderThanAverage(averageLastUpdated, t)) .collect(Collectors.toSet()); }    }