### Question:
StreamService { public void pruneSnapshots(Stream stream) { if (stream.initialRetentionPeriod == null && stream.retentions.isEmpty()) { return; } DateTime now = new DateTime(ISOChronology.getInstanceUTC()); TreeMap<DateTime, Boolean> keepSnapshot = new TreeMap<>(); HashMap<DateTime, Snapshot> snapshotMap = new HashMap<>(); Interval initialRetentionInterval = stream .getInitialRetentionInterval(now); for (Snapshot s : getSnapshots(stream).values()) { keepSnapshot.put(s.date, s.date.isAfter(now) || initialRetentionInterval.contains(s.date)); snapshotMap.put(s.date, s); } for (Retention r : stream.retentions) { for (DateTime time : r.retentionTimes(now)) { DateTime key = keepSnapshot.ceilingKey(time); if (key != null) { keepSnapshot.put(key, true); } } } for (Entry<DateTime, Boolean> entry : keepSnapshot.entrySet()) { if (!entry.getValue()) { deleteSnapshot(snapshotMap.get(entry.getKey())); } } }  Stream readStream(StreamRepository repository, String name); Stream tryReadStream(StreamRepository repository, String name); Stream createStream(StreamRepository streamRepository, String name); void writeVersionHistory(Stream stream); Set<String> getStreamNames(StreamRepository repository); void deleteStream(Path repoLocation, String name); void deleteStream(StreamRepository repo, String name); void deleteStream(Stream stream); void deleteStreams(StreamRepository repository); TreeMap<Integer, Snapshot> getSnapshots(Stream stream); Snapshot takeSnapshot(Stream stream); void restoreLatestSnapshot(Stream stream); void restoreSnapshot(Stream stream, int snapshotNr); void restoreSnapshot(Snapshot snapshot); void deleteSnapshot(Snapshot snapshot); void clearReceiveTempDir(Stream stream); void takeSnapshotIfRequired(Stream stream, Instant now); void pruneSnapshots(Stream stream);  }### Answer:
@Test public void testPruneSnapshots() throws Exception { DateTimeUtils.setCurrentMillisFixed(new DateTime(2014, 1, 1, 0, 0, 0) .getMillis()); Stream stream = service.createStream(repository, "test"); Snapshot snapshot = service.takeSnapshot(stream); DateTimeUtils.setCurrentMillisFixed(new DateTime(2014, 1, 2, 0, 0, 0) .getMillis()); stream.retentions.clear(); stream.initialRetentionPeriod = null; service.pruneSnapshots(stream); assertThat(Files.exists(snapshot.getSnapshotDir()), is(true)); stream.initialRetentionPeriod = Period.minutes(10); service.pruneSnapshots(stream); assertThat(Files.exists(snapshot.getSnapshotDir()), is(false)); }