LogFileProvider { public String getLogContent(final String fileName) { Collection<File> files = getLogFiles(LOG_PATH); File file = findFile(fileName, files); return getContent(file); }  Collection<String> getLogFileNames(); String getLogContent(final String fileName);  }
@Test public void testGetLogContentWhenFileDoesNotExistShouldReturnFileNotFoundMessage() { Collection<File> files = getFileCollection(); String fileName = "non-existent-file"; given(fileUtils.getFilesWithExtension(LOG_PATH, LOG_EXTENSION)).willReturn(files); String result = underTest.getLogContent(fileName); assertEquals(FILE_NOT_FOUND_MESSAGE, result); }
@Test public void testGetLogContent() throws IOException { String expectedFileContent = "content"; Collection<File> files = new ArrayList<>(); String fileName = "a"; File file = new File("a"); files.add(file); given(fileUtils.getFilesWithExtension(LOG_PATH, LOG_EXTENSION)).willReturn(files); given(fileUtils.readFileToString(file)).willReturn(expectedFileContent); String result = underTest.getLogContent(fileName); assertEquals(expectedFileContent, result); }
@Test public void testGetLogContentWhenErrorOccursShouldReturnErrorMessage() throws IOException { Collection<File> files = new ArrayList<>(); String fileName = "a"; File file = new File("a"); files.add(file); given(fileUtils.getFilesWithExtension(LOG_PATH, LOG_EXTENSION)).willReturn(files); given(fileUtils.readFileToString(file)).willThrow(new IOException()); String result = underTest.getLogContent(fileName); assertEquals(ERROR_MESSAGE, result); }