MorePreconditions { public static <X extends Throwable> void checkOrThrow(boolean expression, Supplier<X> exception) throws X { if (!expression) { throw exception.get(); } }  static void checkOrThrow(boolean expression, Supplier<X> exception); static void checkOrThrow(boolean expression, Function<String, X> exception,
            String errorMessageTemplate, Object... errorMessageArgs);  }
@Test void test() throws IOException { checkOrThrow(true, IOException::new, "test"); IOException e = assertThrows(IOException.class, () -> checkOrThrow(false, IOException::new, "test:%s", "1")); assertEquals("test:1", e.getMessage()); e = assertThrows(IOException.class, () -> checkOrThrow(false, IOException::new, "test")); assertEquals("test", e.getMessage()); e = assertThrows(IOException.class, () -> checkOrThrow(false, IOException::new)); assertNull(e.getMessage()); }