Issue
Can I test whether a particular Exception is not thrown?
The other way round is easy using @Test[expect=MyException]
.
But how can I negate this?
Solution
If you want to test if a particular Exception is not thrown in a condition where other exceptions could be thrown, try this:
try {
myMethod();
}
catch (ExceptionNotToThrow entt){
fail("WHOOPS! Threw ExceptionNotToThrow" + entt.toString);
}
catch (Throwable t){
//do nothing since other exceptions are OK
}
assertTrue(somethingElse);
//done!
Answered By - Freiheit
Answer Checked By - Marilyn (JavaFixing Volunteer)