@Test public void testCatchesExceptionHasExceptionSourceInfo() { expectedException.expect(ClusterSourcedException.class); expectedException.expectCause(CoreMatchers.isA(RuntimeException.class)); expectedException.expectMessage("from SOURCE"); expectedException.expect(new CustomMatcher<ClusterSourcedException>("matches the expected exceptionSource: SOURCE") { @Override public boolean matches(Object item) { if (item instanceof ClusterSourcedException) { ClusterSourcedException ex = (ClusterSourcedException) item; return ex.exceptionSource == DiffCluster.Type.SOURCE; } return false; } }); ClusterSourcedException.catches(DiffCluster.Type.SOURCE, () -> { throw new RuntimeException(); }); }
public static <T> T catches(Type exceptionSource, Callable<T> callable) { try { return callable.call(); } catch (Exception ex) { throw new ClusterSourcedException(exceptionSource, ex); } }
ClusterSourcedException extends RuntimeException { public static <T> T catches(Type exceptionSource, Callable<T> callable) { try { return callable.call(); } catch (Exception ex) { throw new ClusterSourcedException(exceptionSource, ex); } } }
ClusterSourcedException extends RuntimeException { public static <T> T catches(Type exceptionSource, Callable<T> callable) { try { return callable.call(); } catch (Exception ex) { throw new ClusterSourcedException(exceptionSource, ex); } } ClusterSourcedException(Type exceptionSource, Throwable cause); }
ClusterSourcedException extends RuntimeException { public static <T> T catches(Type exceptionSource, Callable<T> callable) { try { return callable.call(); } catch (Exception ex) { throw new ClusterSourcedException(exceptionSource, ex); } } ClusterSourcedException(Type exceptionSource, Throwable cause); static T catches(Type exceptionSource, Callable<T> callable); @Override String getMessage(); }
ClusterSourcedException extends RuntimeException { public static <T> T catches(Type exceptionSource, Callable<T> callable) { try { return callable.call(); } catch (Exception ex) { throw new ClusterSourcedException(exceptionSource, ex); } } ClusterSourcedException(Type exceptionSource, Throwable cause); static T catches(Type exceptionSource, Callable<T> callable); @Override String getMessage(); final Type exceptionSource; }