Preconditions { public static void checkArgument(boolean expression, String errorMessage) { com.tngtech.junit.dataprovider.Preconditions.checkArgument(expression, errorMessage); }  static T checkNotNull(T object, String errorMessage); static void checkArgument(boolean expression, String errorMessage); static void checkArgument(boolean expression, String errorMessageFormat, Object... errorMessageArgs);  }
@Test public void testCheckArgumentShouldThrowIllegalArgumentExceptionIfExpressionIsFalse() { String errorMessage = "error message"; expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(errorMessage); Preconditions.checkArgument(1 == 2, errorMessage); }
@Test public void testCheckArgumentShouldNotThrowIllegalArgumentExceptionIfExpressionIsTrue() { Preconditions.checkArgument(true, "error message"); }
@Test public void testCheckArgumentShouldThrowIllegalArgumentExceptionIfExpressionIsFalseAndReturnFormattedMessage() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("error message template"); Preconditions.checkArgument(1 == 2, "error message %s", "template"); }
@Test public void testCheckArgumentShouldNotThrowIllegalArgumentExceptionIfExpressionIsTrueUsingMessageTemplate() { Preconditions.checkArgument(true, "error message %s", "template"); }