The application is throwing 2 different exceptions in some thatMethod(). I'm looking to test it by JUnit.
I can use ExpectedException and @Rule to set aside a "natural" exception the application is expected to throw. How do you assert that a certain exception is thrown in JUnit 4 tests? is explaining this.
How can i do that in my case-- 2 or more "natural" exceptions? ExpectedException is not holding multiple expected exceptions.
There are other ways to do this-- as explained in How do you assert that a certain exception is thrown in JUnit 4 tests? again. i'm wondering whether there is a way to do this by using the built-in features of JUnit.
A single test method can only exit once, and so can only throw a single exception. If you wish to confirm that your code can fail in two different ways then you have two separate tests; split it into two test methods and declare the specific exception on each.