### Question:
ExceptionUtils { @Nullable public static Throwable findCause( @Nonnull Throwable exception, @Nonnull Class<?>... causeClasses ) { final Set<Throwable> checkedCauses = new HashSet<>(); Throwable cause = exception; do { if ( isInstance( cause, causeClasses ) ) { break; } checkedCauses.add( cause ); cause = cause.getCause(); } while ( (cause != null) && !checkedCauses.contains( cause ) ); return cause; } private  ExceptionUtils(); @Nullable static Throwable findCause( @Nonnull Throwable exception, @Nonnull Class<?>... causeClasses );  }### Answer:
@Test public void findCauseItself() { final IllegalArgumentException exception = new IllegalArgumentException( "Test" ); Assert.assertSame( exception, ExceptionUtils.findCause( exception, IllegalArgumentException.class ) ); }
@Test public void findCauseNotFound() { final IllegalArgumentException exception = new IllegalArgumentException( "Test", new PatternSyntaxException( "Test", "xxx", 1 ) ); Assert.assertNull( ExceptionUtils.findCause( exception, NumberFormatException.class ) ); }
@Test public void findCauseFound() { final PatternSyntaxException found = new PatternSyntaxException( "Test", "xxx", 1 ); final IllegalArgumentException exception = new IllegalArgumentException( "Test", found ); Assert.assertSame( found, ExceptionUtils.findCause( exception, NumberFormatException.class, PatternSyntaxException.class ) ); }