I had a specific error state that I wanted the tests to detect. I simulate that state in the state of the test, and need my code to have thrown a specific exception.
assertThrows( IllegalStateException.class,
() -> instance.method(argOne, argTwo)
);
assertThrows is the tool to use in Juniper 5. You set up the preconditions for the method invocation to call, then with the arguments of assertThrows
, you specify the exception class that would be thrown, and you make the invocation. () -> instance.method(argOne, argTwo);
In the preconditions, I had set a bad condition on one of the arguments that the instance.method
is working with. Say argOne.invoiceType = a disallowed type
.