Skip to content

Commit

Permalink
Document benefits of MessageSupplier in Assertions Issue: junit-team#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitwasankar committed Jan 10, 2024
1 parent 2a291a1 commit 8ebf479
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions documentation/src/test/java/example/AssertionsDemo.java
Expand Up @@ -39,10 +39,14 @@ class AssertionsDemo {
@Test
void standardAssertions() {
assertEquals(2, calculator.add(1, 1));
// When assertion failure message is used as a plain expression,
// the expression will be evaluated irrespective of the assertion result.
assertEquals(4, calculator.multiply(2, 2),
"The optional failure message is now the last parameter");
assertTrue('a' < 'b', () -> "Assertion messages can be lazily evaluated -- "
+ "to avoid constructing complex messages unnecessarily.");
"This expression will always evaluate irrespective of assertion result.");
// When assertion failure message is created as a lambda expression,
// expression will only evaluate when assertion result is failed (lazy evaluation)
// and can help us save unnecessary computations when they are not needed.
assertTrue('a' < 'b', () -> "This lambda will evaluate only if assertion fails.");
}

@Test
Expand Down

0 comments on commit 8ebf479

Please sign in to comment.