diff --git a/src/test/java/lambdas/LazyErrorMessageTest.java b/src/test/java/lambdas/LazyErrorMessageTest.java index 4b7b681..12354f3 100644 --- a/src/test/java/lambdas/LazyErrorMessageTest.java +++ b/src/test/java/lambdas/LazyErrorMessageTest.java @@ -2,24 +2,34 @@ import org.junit.jupiter.api.Test; +import java.util.logging.Logger; + import static org.junit.jupiter.api.Assertions.assertTrue; public class LazyErrorMessageTest { + private final Logger logger = Logger.getLogger(LazyErrorMessageTest.class.getName()); private String getErrorMessage() { System.out.println("Generating error message..."); return "x should be true"; } + private String getLogMessage() { + System.out.println("Generating log message..."); + return "log message"; + } + @Test - void assertArgIsTrue() { + void assertArgIsTrue_eager() { boolean x = true; assertTrue(x, getErrorMessage()); // 2nd arg is a String + logger.fine(getLogMessage()); } @Test - void assertArgIsTrue_lazyErrorMessage() { + void assertArgIsTrue_lazy() { boolean x = true; assertTrue(x, () -> getErrorMessage()); // 2nd arg is a Supplier + logger.fine(() -> getLogMessage()); } }