I am writing some JUnit tests that verify that an exception of type MyCustomException is thrown. However, this exception is wrapped in other exceptions a number of
MyCustomException
You can do this using guava:
FluentIterable.from(Throwables.getCausalChain(e)) .filter(Predicates.instanceOf(ConstraintViolationException.class)) .first() .isPresent();