Issue
I know that one can define an 'expected' exception in JUnit, doing:
@Test(expect=MyException.class)
public void someMethod() { ... }
But what if there is always same exception thrown, but with different 'nested' causes.
Any suggestions?
Solution
You could wrap the testing code in a try / catch block, catch the thrown exception, check the internal cause, log / assert / whatever, and then rethrow the exception (if desired).
Answered By - Paul Sonier
Answer Checked By - Candace Johnson (JavaFixing Volunteer)