@Test public final void testBuildMessageFileListJsonShouldCreateEmptyJsonWhenDirectoryIsNotADirectory() { String expected = "{\"files\":[]}"; given(file.list()).willReturn(null); String actual = underTest.buildMessageFileListJson(file, 5); assertEquals(actual, expected); }
public String buildMessageFileListJson(final File directory, final int maxValue) { String result = "{\"files\":[]}"; String[] messageFiles = directory.list(); if (messageFiles != null) { String[] resultFiles = messageFiles; Arrays.sort(resultFiles); if (messageFiles.length > maxValue) { resultFiles = Arrays.copyOfRange(messageFiles, resultFiles.length - maxValue, resultFiles.length); } result = getJson(resultFiles); } else { logger.debug("The directory '" + directory + "' has not been created yet, or an I/O error occured."); } return result; }
FileListJsonBuilder { public String buildMessageFileListJson(final File directory, final int maxValue) { String result = "{\"files\":[]}"; String[] messageFiles = directory.list(); if (messageFiles != null) { String[] resultFiles = messageFiles; Arrays.sort(resultFiles); if (messageFiles.length > maxValue) { resultFiles = Arrays.copyOfRange(messageFiles, resultFiles.length - maxValue, resultFiles.length); } result = getJson(resultFiles); } else { logger.debug("The directory '" + directory + "' has not been created yet, or an I/O error occured."); } return result; } }
FileListJsonBuilder { public String buildMessageFileListJson(final File directory, final int maxValue) { String result = "{\"files\":[]}"; String[] messageFiles = directory.list(); if (messageFiles != null) { String[] resultFiles = messageFiles; Arrays.sort(resultFiles); if (messageFiles.length > maxValue) { resultFiles = Arrays.copyOfRange(messageFiles, resultFiles.length - maxValue, resultFiles.length); } result = getJson(resultFiles); } else { logger.debug("The directory '" + directory + "' has not been created yet, or an I/O error occured."); } return result; }  }
FileListJsonBuilder { public String buildMessageFileListJson(final File directory, final int maxValue) { String result = "{\"files\":[]}"; String[] messageFiles = directory.list(); if (messageFiles != null) { String[] resultFiles = messageFiles; Arrays.sort(resultFiles); if (messageFiles.length > maxValue) { resultFiles = Arrays.copyOfRange(messageFiles, resultFiles.length - maxValue, resultFiles.length); } result = getJson(resultFiles); } else { logger.debug("The directory '" + directory + "' has not been created yet, or an I/O error occured."); } return result; }  String buildLogFileListJson(final File directory); String buildMessageFileListJson(final File directory, final int maxValue); String buildFileListJson(final File directory); }
FileListJsonBuilder { public String buildMessageFileListJson(final File directory, final int maxValue) { String result = "{\"files\":[]}"; String[] messageFiles = directory.list(); if (messageFiles != null) { String[] resultFiles = messageFiles; Arrays.sort(resultFiles); if (messageFiles.length > maxValue) { resultFiles = Arrays.copyOfRange(messageFiles, resultFiles.length - maxValue, resultFiles.length); } result = getJson(resultFiles); } else { logger.debug("The directory '" + directory + "' has not been created yet, or an I/O error occured."); } return result; }  String buildLogFileListJson(final File directory); String buildMessageFileListJson(final File directory, final int maxValue); String buildFileListJson(final File directory);  }