July 2023
Intermediate to advanced
276 pages
6h 55m
English
When Java 5 annotations were introduced, JUnit[13] was quick to use them. Overall this was a benefit, but one use in particular, the convenience of exception tests, led to terse rather than concise code. Let’s understand the issues and then resolve them using—good guess—lambda expressions. We’ll see here that lambda expressions aren’t just another language feature; they alter the way we think, design, and even test applications.
Suppose we’re driving the design of a class, RodCutter, through unit tests and we expect a maxProfitmethod to throw an exception if the argument is zero. Let’s look at a few ways we can write the exception tests for it.
Here’s a test for the ...
Read now
Unlock full access