I try to test exception thrown by a method like this:
Assertions.assertThatThrownBy( () -> myMethod(paramA, paramB))
.isInstanceOf(IllegalArgumentException.class).hasMessage(error);
However the problem is I still need to make more assertions on the return value of myMethod()
without having to invoke it again separately. Since it is a lambda, I cannot assign the return value to external variable without a compile error.
How do I capture and make assertions on the return value of myMethod()
without having to make another call?