Utils { static void warnOrAssert(Logger logger, String message, Object... args) { if (ASSERT) { FormattingTuple detailMessage = MessageFormatter.arrayFormat(message, args); Throwable throwable = detailMessage.getThrowable(); throw throwable == null ? new AssertionError(detailMessage.getMessage()) : new AssertionError(detailMessage.getMessage(), throwable); } else { try { WARN.invokeExact(logger, message, args); } catch (Throwable throwable) { throw new AssertionError(); } } }    }
@Test(expected = AssertionError.class) public void warnOrAssert() throws Exception { Logger logger = LoggerFactory.getLogger("toto"); Utils.warnOrAssert(logger, "Hello {} and {}", "men", "women", new RuntimeException()); }