### Question:
TimeBasedArchiveRemover extends ContextAwareBase implements ArchiveRemover { public void clean(final Date now) { List<String> files = this.findFiles(); List<String> expiredFiles = this.filterFiles(files, this.createExpiredFileFilter(now)); for (String f : expiredFiles) { this.delete(new File(f)); } if (this.totalSizeCap != CoreConstants.UNBOUNDED_TOTAL_SIZE_CAP && this.totalSizeCap > 0) { this.capTotalSize(files); } List<String> emptyDirs = this.findEmptyDirs(); for (String dir : emptyDirs) { this.delete(new File(dir)); } } TimeBasedArchiveRemover(FileNamePattern fileNamePattern, RollingCalendar rc, FileProvider fileProvider); void clean(final Date now); void setMaxHistory(int maxHistory); void setTotalSizeCap(long totalSizeCap); String toString(); Future<?> cleanAsynchronously(Date now);  }### Answer:
@Test public void removesOnlyExpiredFiles() { remover.clean(EXPIRY); for (File f : expiredFiles) { verify(fileProvider).deleteFile(f); } for (File f : recentFiles) { verify(fileProvider, never()).deleteFile(f); } }
@Test public void removesParentDirWhenEmpty() throws IOException { File[] emptyDirs = new File[] { tmpDir.newFolder("empty_2018", "08"), tmpDir.newFolder("empty_2018", "12"), tmpDir.newFolder("empty_2019", "01"), }; for (File d : emptyDirs) { d.deleteOnExit(); } remover = mockArchiveRemover(tmpDir.getRoot().getAbsolutePath() + File.separator + "empty_%d{yyyy/MM}" + File.separator + "%d.log", fileProvider); remover.clean(EXPIRY); for (File d : emptyDirs) { verify(fileProvider).deleteFile(d); } }
@Test public void keepsParentDirWhenNonEmpty() { remover.clean(new Date(0)); verify(fileProvider, never()).deleteFile(any(File.class)); }
@Test public void removesOlderFilesThatExceedTotalSizeCap() { setupSizeCapTest(); remover.clean(EXPIRY); for (File f : Arrays.asList(expiredFiles).subList(MAX_HISTORY - NUM_FILES_TO_KEEP, expiredFiles.length)) { verify(fileProvider).deleteFile(f); } }
@Test public void keepsRecentFilesAndOlderFilesWithinTotalSizeCap() { setupSizeCapTest(); remover.clean(EXPIRY); for (File f : recentFiles) { verify(fileProvider, never()).deleteFile(f); } for (File f : Arrays.asList(expiredFiles).subList(0, MAX_HISTORY - NUM_FILES_TO_KEEP)) { verify(fileProvider, never()).deleteFile(f); } }