Checks { public static void checkState(boolean condition, String message) throws IllegalStateException { if (!condition) { throw new IllegalStateException(message); } }  static T checkNotNull(T value); static void checkArgument(boolean condition, String message); static void checkArgument(boolean condition, String message, Object... args); static void checkState(boolean condition, String message); static void checkState(boolean condition, String message, Object... args); static void checkNotNullState(Object object, String message); static void checkNotNullState(Object object, String message, Object... args); static void checkMinMax(int min, int max); static int checkMin(int min); static int checkMax(int max); static int checkNonNegative(int n, String message);  }
@Test public void checkState_noThrowIfConditionIsTrue() { Checks.checkState(true, "whatever"); Checks.checkState(true, "whatever", 1, 2); Checks.checkState(true, "bad format %s and %s", 1); }
@Test public void checkState_throwsIfConditionIsFalse() { exception.expect(IllegalStateException.class); exception.expectMessage("one = 1"); Checks.checkState(false, "one = %s", 1); }