Skip to content

Commit

Permalink
Add FileFilterTest class and remove redundant annotation
Browse files Browse the repository at this point in the history
A new test class FileFilterTest.java to test various scenarios of file filtering has been added in the lambdas package. Additionally, a redundant "@SuppressWarnings("DuplicatedCode")" annotation has been removed from ProcessDictionary.java.
  • Loading branch information
kousen committed May 21, 2024
1 parent 95f4bfc commit 7d551c0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/main/java/io/ProcessDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;

@SuppressWarnings("DuplicatedCode")
public class ProcessDictionary {
private final Path dictionary = Paths.get("/usr/share/dict/words");

Expand Down
56 changes: 56 additions & 0 deletions src/test/java/lambdas/FileFilterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package lambdas;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileFilter;

import static org.assertj.core.api.Assertions.assertThat;

public class FileFilterTest {
private final File root = new File("src/main/java");

@Test
void listFiles() {
File[] files = root.listFiles();
assertThat(files)
.isNotNull()
.isNotEmpty()
.hasSize(22);
}

@Test
void listDirectories_anonInnerClass() {
File[] directories = root.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
assertThat(directories)
.isNotNull()
.isNotEmpty()
.hasSize(14);
}

@Test
void listDirectories_expressionLambda() {
File[] directories = root.listFiles(pathname -> pathname.isDirectory());
assertThat(directories)
.isNotNull()
.isNotEmpty()
.hasSize(14);
}

@Test
void listDirectories_blockLambda() {
File[] directories = root.listFiles(pathname -> {
System.out.println("Checking " + pathname);
return pathname.isDirectory();
});
assertThat(directories)
.isNotNull()
.isNotEmpty()
.hasSize(14);
}
}

0 comments on commit 7d551c0

Please sign in to comment.