When testing code like this (combining mockito + assertJ + mockito-java8), with some assertJ JSON psuedo-code:
verify(myObject.someMethod(assertArg(s -> {
assertThat(s).isJSON();
assertThat(Jackson.parseJSON(s)).hasProperty("foo"); // throws JSONParseException
});
If Jackson.parseJSON throws a checked exception, the compiler wants me to catch it inside the lambda. However, that exception should just fail the test, since like any other exception, it means something unexpected has gone wrong.
Hence, I suggest assertArg be widened to take a CheckedConsumer<T> type:
@FunctionalInterface
interface CheckedConsumer<T> {
void accept(T value) throws Throwable;
}
When testing code like this (combining mockito + assertJ + mockito-java8), with some assertJ JSON psuedo-code:
If
Jackson.parseJSONthrows a checked exception, the compiler wants me to catch it inside the lambda. However, that exception should just fail the test, since like any other exception, it means something unexpected has gone wrong.Hence, I suggest
assertArgbe widened to take aCheckedConsumer<T>type: