ExceptionUtil { public static <E extends Exception> void perform(Class<E> cls, PerformAction action) throws E { try { action.action(); } catch (Exception e) { throw prepareException(cls, e.getMessage(), e); } }  static void perform(Class<E> cls, PerformAction action); static T perform(Class<E> cls, PerformResult<T> action); static T perform(Class<E> cls, String message, PerformResult<T> action);  }
@Test public void simpleNoException() throws Exception { ExceptionUtil.perform(Exception.class, () -> { }); ExceptionUtil.perform(Exception.class, () -> null); ExceptionUtil.perform(Exception.class, "Not to be thrown.", () -> null); }
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "1337") public void simpleThrowIOException() throws Exception { ExceptionUtil.perform(IOException.class, () -> { throw new Exception("1337"); }); }
@Test(expectedExceptions = PeppolException.class, expectedExceptionsMessageRegExp = "42") public void simpleThrowPeppolException() throws Exception { ExceptionUtil.perform(PeppolException.class, () -> { throw new Exception("42"); }); }
@Test(expectedExceptions = PeppolRuntimeException.class, expectedExceptionsMessageRegExp = "1000") public void simpleThrowPeppolRuntimeException() throws Exception { ExceptionUtil.perform(PeppolRuntimeException.class, "1000", () -> { throw new Exception("2000"); }); }
@Test(expectedExceptions = PeppolRuntimeException.class) public void simpleTooSimpleExtension() throws Exception { ExceptionUtil.perform(SimpleExtension.class, () -> { throw new Exception("Test"); }); }