Java Utililty Methods Assert

List of utility methods to do Assert

Description

The list of methods to do Assert are organized into topic(s).

Method

voidassertCheckStrAndQuery(String str, String query)
Checks that str is not null, and query is not null, not empty, and is a single word.
assert str != null : STR_CANNOT_BE_NULL_MESSAGE;
assert query != null : QUERY_CANNOT_BE_NULL_MESSAGE;
assert !query.isEmpty() : QUERY_CANNOT_BE_EMPTY_MESSAGE;
assert query.split(WHITESPACE_DELIMITER).length == 1 : QUERY_LEN_SHOULD_BE_ONE_MESSAGE;
voidassertClassDoesNotExist(String className)
assert Class Does Not Exist
try {
    Class.forName(className);
    throw new AssertionError("Expected a class to not exists, but it did: " + className);
} catch (ClassNotFoundException e) {
voidassertClassExists(String className)
assert Class Exists
try {
    Class.forName(className);
} catch (ClassNotFoundException e) {
    throw new AssertionError("Expected a class to exists, but it did not: " + className, e);
voidassertColor(int color)
assert Color
if (color < 0 || color > 255) {
    throw new IllegalArgumentException("Color outside of range 0 - 255");
booleanassertComparison(T actual, T expected)
assert Comparison
boolean ret = false;
if ((expected == null) && (actual == null)) {
    ret = true;
} else if (expected != null) {
    ret = expected.compareTo(actual) == 0;
return ret;
booleanassertComparison(T actual, T expected)
assert the equality of two generic objects using compareTo() operator
boolean ret = false;
if ((expected == null) && (actual == null)) {
    ret = true;
} else if (expected != null) {
    ret = expected.compareTo(actual) == 0;
return ret;
voidassertCond(boolean b)
assert Cond
if (!b)
    throw new RuntimeException("Assertion violation.");
voidassertCondition(boolean condition, String message)
Assert the provided boolean condition , throwing AssertionError with the supplied message if the test result is false .
if (!condition) {
    fail(message);
voidassertCondition(boolean condition, String msg)
assert Condition
if (!condition) {
    throw new InternalError("Assertion failed: " + msg);
voidassertContains(final String string, final String content)
Checks that the expected string occurs within the content string.
if (content.indexOf(string) == -1) {
    throw new AssertionError(content + "' does not contain '" + string + "'");