-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FileFilterTest class and remove redundant annotation
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
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |