### Question:
DataPurgeServiceImpl implements DataPurgeService { @Override public boolean purgeData(DataPurgeConfig dataPurgeConfig, DateTime currentTime) { if (!validatePurgeParameters(dataPurgeConfig, currentTime)) { return false; } DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dataPurgeConfig.getDatePathFormat()); DateTime oldestDataAllowed; if (dataPurgeConfig.getMaxAgeInDays() > 0) { oldestDataAllowed = currentTime.plusDays(-dataPurgeConfig.getMaxAgeInDays()); } else { oldestDataAllowed = currentTime.plusHours(-dataPurgeConfig.getMaxAgeInHours()); } logger.debug("Oldest data allowed {} , current time is {}", new Object[]{oldestDataAllowed, currentTime}); for (String directoryPrefix : dataPurgeConfig.getDirectoryPrefix()) { for (File prefixDirectory : expandPrefix(directoryPrefix)) { List<File> subdirectories = getSubdirectoryList(prefixDirectory, null); for (File subdirectory : subdirectories) { logger.trace("Considering directory {} for purge", subdirectory); safeDelete(prefixDirectory.getPath(), dateTimeFormatter, oldestDataAllowed, subdirectory, dataPurgeConfig.isFileBasedPurge(), dataPurgeConfig.getDateStartIndex(), dataPurgeConfig.getDateStringLength()); } if (dataPurgeConfig.getCleanEmptyParents()) { for (File directory : subdirectories) { if (directory.list() != null && directory.list().length == 0) { try { FileUtils.deleteDirectory(directory); } catch (IOException e) { logger.warn("Failed to delete empty directory {}", directory); } } } } } } return true; } DataPurgeServiceImpl(); @Override boolean purgeData(DataPurgeConfig dataPurgeConfig, DateTime currentTime);  }### Answer:
@Test public void testArgumentValidation() throws Exception { DataPurgeConfig dataPurgeConfig = new DataPurgeConfig(); dataPurgeConfig.setMaxAgeInDays(1); assertFalse(dataPurgeService.purgeData(dataPurgeConfig, new DateTime())); dataPurgeConfig.setDirectoryPrefix(new String[]{"base"}); assertFalse(dataPurgeService.purgeData(dataPurgeConfig, new DateTime())); dataPurgeConfig.setDatePathFormat("yy/MM/dd"); assertFalse(dataPurgeService.purgeData(dataPurgeConfig, null)); dataPurgeConfig.setMaxAgeInDays(-1); assertFalse(dataPurgeService.purgeData(dataPurgeConfig, new DateTime())); dataPurgeConfig.setMaxAgeInDays(1); dataPurgeConfig.setDatePathFormat(null); assertFalse(dataPurgeService.purgeData(dataPurgeConfig, new DateTime())); dataPurgeConfig.setDatePathFormat("yy/MM/dd"); dataPurgeConfig.setFileBasedPurge(true); assertFalse(dataPurgeService.purgeData(dataPurgeConfig, new DateTime())); dataPurgeConfig.setDateStartIndex(2); assertFalse(dataPurgeService.purgeData(dataPurgeConfig, new DateTime())); dataPurgeConfig.setDateStringLength(4); assertTrue(dataPurgeService.purgeData(dataPurgeConfig, new DateTime())); }
@Test public void testPurgeData() throws IOException { String prefix = getPrefix() + "/dptest"; createData(prefix); DateTimeFormatter formatter = DateTimeFormat.forPattern("yy/MM/dd"); DateTime currentTime = formatter.parseDateTime("11/01/04"); DataPurgeConfig dataPurgeConfig = new DataPurgeConfig(); dataPurgeConfig.setMaxAgeInDays(1); dataPurgeConfig.setDirectoryPrefix(new String[]{prefix}); dataPurgeConfig.setDatePathFormat("yy/MM/dd"); assertTrue(dataPurgeService.purgeData(dataPurgeConfig, currentTime)); List<File> directoryList = dataPurgeService.getSubdirectoryList(new File(prefix), null); assertNotNull(directoryList); assertEquals(7, directoryList.size()); }