From 7fb1d38eec331f8148712521c87f4a3ba309638e Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Tue, 29 Nov 2022 23:15:10 +0100 Subject: [PATCH] Improve naming. --- .../plugins/util/AgentFileVisitor.java | 5 ++-- .../plugins/util/AgentFileVisitorTest.java | 23 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/util/AgentFileVisitor.java b/src/main/java/io/jenkins/plugins/util/AgentFileVisitor.java index 3734dda..d5fef04 100644 --- a/src/main/java/io/jenkins/plugins/util/AgentFileVisitor.java +++ b/src/main/java/io/jenkins/plugins/util/AgentFileVisitor.java @@ -48,14 +48,15 @@ public abstract class AgentFileVisitor /** * Creates a new instance of {@link AgentFileVisitor}. + * * @param filePattern * ant file-set pattern to scan for files to parse * @param encoding * encoding of the files to parse * @param followSymbolicLinks - * if the scanner should traverse symbolic links + * determines whether the visitor should traverse symbolic links * @param errorOnEmptyFiles - * if the true is configured log Error if not log Info message + * determines whether the visitor should log errors if a file is empty */ protected AgentFileVisitor(final String filePattern, final String encoding, final boolean followSymbolicLinks, final boolean errorOnEmptyFiles) { this(filePattern, encoding, followSymbolicLinks, errorOnEmptyFiles, new FileSystemFacade()); diff --git a/src/test/java/io/jenkins/plugins/util/AgentFileVisitorTest.java b/src/test/java/io/jenkins/plugins/util/AgentFileVisitorTest.java index 376ad5d..6307f76 100644 --- a/src/test/java/io/jenkins/plugins/util/AgentFileVisitorTest.java +++ b/src/test/java/io/jenkins/plugins/util/AgentFileVisitorTest.java @@ -91,8 +91,8 @@ void shouldReturnMultipleResults(final boolean followLinks, final String message } @Test - @DisplayName("Should handle empty or forbidden files") - void shouldReturnMultipleResults() { + @DisplayName("Should log error for empty or forbidden files") + void shouldLogErrorForEmptyAndForbiddenFiles() { FileSystemFacade fileSystemFacade = createFileSystemFacade(true, "/one.txt", "/two.txt", "empty.txt", "not-readable.txt"); @@ -121,33 +121,28 @@ void shouldReturnMultipleResults() { } @Test - @DisplayName("Should handle empty or forbidden files and info on Empty Files") - void shouldReturnMultipleResultsAndInfoOnEmptyFiles() { + @DisplayName("Should skip logging of errors when parsing empty files") + void shouldSkipLoggingOfErrorsForEmptyFiles() { FileSystemFacade fileSystemFacade = createFileSystemFacade(true, - "/one.txt", "/two.txt", "empty.txt", "not-readable.txt"); + "/one.txt", "/two.txt", "empty.txt"); Path empty = workspace.toPath().resolve("empty.txt"); when(fileSystemFacade.resolve(workspace, "empty.txt")).thenReturn(empty); when(fileSystemFacade.isEmpty(empty)).thenReturn(true); - Path notReadable = workspace.toPath().resolve("not-readable.txt"); - when(fileSystemFacade.resolve(workspace, "not-readable.txt")).thenReturn(notReadable); - when(fileSystemFacade.isNotReadable(notReadable)).thenReturn(true); - StringScanner scanner = new StringScanner(PATTERN, "UTF-8", true, false, fileSystemFacade); - ScannerResult actualResult = scanner.invoke(workspace, null); + FileVisitorResult actualResult = scanner.invoke(workspace, null); assertThat(actualResult.getResults()).containsExactly(CONTENT + 1, CONTENT + 2); assertThat(actualResult.getLog().getInfoMessages()).contains( "Searching for all files in '/absolute/path' that match the pattern '**/*.txt'", - "-> found 4 files", + "-> found 3 files", "Successfully processed file '/one.txt'", "Successfully processed file '/two.txt'", "Skipping file 'empty.txt' because it's empty"); - assertThat(actualResult.hasErrors()).isTrue(); - assertThat(actualResult.getLog().getErrorMessages()).containsExactly("Errors during parsing", - "Skipping file 'not-readable.txt' because Jenkins has no permission to read the file"); + assertThat(actualResult.hasErrors()).isFalse(); + assertThat(actualResult.getLog().getErrorMessages()).isEmpty(); } private FileSystemFacade createFileSystemFacade(final boolean followLinks, final String... files) {