List of utility methods to do Assert
void | assertInstanceOf(Object obj, Class classType) assert Instance Of if (obj == null) { throw new IllegalArgumentException("Argument is null!"); if (!classType.isInstance(obj)) { throw new IllegalArgumentException("Argument should be instance of " + classType.getName() + ", but now is " + obj.getClass().getName()); |
void | assertInstanceOf(Object obj, Class> expClass) Checks if the passed object is of the class specified, null values are ignored if (obj == null) return; if (!(expClass.isAssignableFrom(obj.getClass()))) { throw new AssertionError( "Expected class: " + expClass.getName() + " but object has class: " + obj.getClass().getName()); |
void | assertInstanceOf(Object object, Class> expectClass) assert Instance Of boolean b = expectClass.isInstance(object); if (b == false) { throw new AssertionError(String.format("The expect class is %s, but actually %s.", expectClass.getName(), object.getClass().getName())); |
void | assertIntegerGreaterThanZero(long number, String name) Check if the integer is greater than zero. if (number <= 0) { throw new IllegalArgumentException(name + " must be positive."); |
void | assertIntegerNotNegative(String message, int num) assert Integer Not Negative if (num < 0) { throw new IllegalArgumentException(message); |
void | assertion(boolean isTrue, String reason) If false, throw an assertException, and give a reason if (!isTrue) { throw new RuntimeException(reason); |
void | assertion(boolean value) assertion if (!value) throw new RuntimeException("Assertion failed."); |
String | assertion(String operator, String expr) assertion return "(assert (" + operator + " " + toBool(expr) + "))\n"; |
RuntimeException | assertionError(String message, Object... args) Returns a RuntimeException with a formatted error message. return assertionError(null, message, args);
|
AssertionError | assertionError(String message, Throwable cause) assertion Error AssertionError error = new AssertionError(message); error.initCause(cause); throw error; |