-
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.
Added enhancements and new tests in 'FileFilterTest.java' and a new f…
…ile 'LazySupplierTest.java' Enhanced 'FileFilterTest.java' by adding code that includes new tests and methods for directory listing and '.java' files filtering using lambda expressions and method references. The reason for these enhancements is to validate the correct functionality of file fiters with lambda expressions and method references in addition to anonymous inner classes. Further, a new test file 'LazySupplierTest.java' has been introduced in the lamdabas package to test Lazy supplier performance. This is to ensure that 'Supplier' actually provides lazy behaviour when using Lambda expressions, which are part of Java8 language improvements.
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
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,35 @@ | ||
package lambdas; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.logging.Logger; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class LazySupplierTest { | ||
private final Logger logger = Logger.getLogger(LazySupplierTest.class.getName()); | ||
|
||
private String getErrorMessage() { | ||
System.out.println("getErrorMessage() called"); | ||
return "Error message"; | ||
} | ||
|
||
private String getLogMessage() { | ||
System.out.println("getLogMessage() called"); | ||
return "Log message"; | ||
} | ||
|
||
@Test | ||
void eagerErrorMessage() { | ||
boolean x = true; | ||
logger.fine(getLogMessage()); | ||
assertTrue(x, getErrorMessage()); | ||
} | ||
|
||
@Test | ||
void lazyErrorMessage() { | ||
boolean x = true; | ||
logger.fine(() -> getLogMessage()); | ||
assertTrue(x, () -> getErrorMessage()); | ||
} | ||
} |