List of utility methods to do Assert
void | assertParameterWithinBounds(String name, long lower, long upper, long parameter) assert Parameter Within Bounds if (parameter < lower || parameter > upper) { throw new IllegalArgumentException( String.format("Invalid %s: %d (expected: %d <= n < %d)", name, parameter, lower, upper + 1)); |
void | assertPasswordMeetsRequirements(String password, boolean expected) assert Password Meets Requirements boolean actual = passwordMeetsRequirements(password); String quotedPassword = (password == null) ? "null" : "\"" + password + "\""; String output = "passwordMeetsRequirements(" + quotedPassword + ") = " + actual; if (actual == expected) { output += " (expected)"; } else { output += ", expected " + expected + ". NOOOOOOOOOOOOOOOOOOOOOOOOOO!"; System.out.println(output); |
void | assertPositive(int num, String err) assert Positive if (num <= 0) { throw new RuntimeException(err); |
void | assertPositive(int val, String msg) Checks what value is positive. if (val < 0) { throw new IllegalArgumentException(msg); |
void | assertPositive(int value) throws an IllegalArgumentException if the value is smaller then 0 if (value < 0) { throw new IllegalArgumentException("value is smaller then 0"); |
void | assertPrecondition(boolean b) Checks that a precondition (declared using the javadoc @pre tag) is satisfied.
assertTrue(b); |
void | assertQualifiedString(String str, String argName) assert Qualified String if (!isQualifiedString(str)) { throw new IllegalArgumentException( "Null or zero length string found. str[" + str + "] argumentName[" + argName + "]"); |
double | assertRange(String label, double value, double min, double max) assert Range if (value < min || value > max) { throw new IllegalArgumentException( String.format("%s must be between %f and %f. Value was: %f", label, min, max, value)); return value; |
void | assertRequiredArgs(Object[] methodArgs, int requiredArgs, String methodName) assert Required Args if (methodArgs == null) { throw new IllegalArgumentException( String.format("Expected %d arguments for %s, got 0", requiredArgs, methodName)); } else if (methodArgs.length < requiredArgs) { throw new IllegalArgumentException(String.format("Expected %d arguments for %s, got %d", requiredArgs, methodName, methodArgs.length)); |
void | assertSame(Object expected, Object actual) assert Same if (expected != actual) throw new AssertionError(); |