diff --git a/src/main/java/io/ProcessDictionary.java b/src/main/java/io/ProcessDictionary.java index 91aaeec..1b34afd 100644 --- a/src/main/java/io/ProcessDictionary.java +++ b/src/main/java/io/ProcessDictionary.java @@ -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"); diff --git a/src/test/java/lambdas/FileFilterTest.java b/src/test/java/lambdas/FileFilterTest.java new file mode 100644 index 0000000..5ae463d --- /dev/null +++ b/src/test/java/lambdas/FileFilterTest.java @@ -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); + } +}