FileListJsonBuilder { public String buildLogFileListJson(final File directory) { String result = "{\"files\":[]}"; String[] messageFiles = directory.list(); if (messageFiles != null) { Arrays.sort(messageFiles); result = getJson(messageFiles); } 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);  }
@Test public final void testBuildLogFileListJsonShouldCreateProperJson() { String expected = "{\"files\":[\"20130829103650.0000resp.txt\",\"20130829103651.0000req.txt\"]}"; String[] fileNames = {"20130829103651.0000req.txt", "20130829103650.0000resp.txt"}; given(file.list()).willReturn(fileNames); String actual = underTest.buildLogFileListJson(file); assertEquals(actual, expected); }
@Test public final void testBuildLogFileListJsonShouldCreateProperJsonWhenNoFilesAvailable() { String expected = "{\"files\":[]}"; String[] fileNames = {}; given(file.list()).willReturn(fileNames); String actual = underTest.buildLogFileListJson(file); assertEquals(actual, expected); }
@Test public final void testBuildLogFileListJsonShouldCreateEmptyJsonWhenDirectoryIsNotADirectory() { String expected = "{\"files\":[]}"; given(file.list()).willReturn(null); String actual = underTest.buildLogFileListJson(file); assertEquals(actual, expected); }