FileListJsonBuilder { public String buildFileListJson(final File directory) { String result = "{\"files\":[]}"; Collection<File> messageFiles = fileUtilsWrapper.listFiles(directory); if (messageFiles != null) { List<String> fileNames = getFileNames(messageFiles); Collections.sort(fileNames); result = getJson(fileNames); } else { logger.debug("The directory '" + directory + "' has not been created yet, or an I/O error occurred."); } return result; }  String buildLogFileListJson(final File directory); String buildMessageFileListJson(final File directory, final int maxValue); String buildFileListJson(final File directory);  }
@Test public final void testBuildFileListJsonShouldCreateProperJsonWhenDirectoryIncluded() { String expected = "{\"files\":[\"File1.class\",\"File2.class\",\"File3.class\"]}"; Collection<File> filesInDirectory = new ArrayList<File>(); filesInDirectory.add(new File("folder/File1.class")); filesInDirectory.add(new File("folder/File2.class")); filesInDirectory.add(new File("folder/File3.class")); given(fileUtilsWrapper.listFiles(directory)).willReturn(filesInDirectory); String result = underTest.buildFileListJson(directory); assertEquals(result, expected); }
@Test public final void testBuildFileListJsonShouldCreateProperJsonWhenNoFilesAvailable() { String expected = "{\"files\":[]}"; String[] fileNames = {}; given(file.list()).willReturn(fileNames); String actual = underTest.buildFileListJson(file); assertEquals(actual, expected); }
@Test public final void testBuildFileListJsonShouldEmptyJsonWhenDirectoryIsNotADirectory() { String expected = "{\"files\":[]}"; given(file.list()).willReturn(null); String actual = underTest.buildFileListJson(file); assertEquals(actual, expected); }