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

voidassertFails(Class expectedThrowable, String pattern, int... values)
assert Fails
try {
    getData(pattern, values);
    StringBuilder sb = new StringBuilder();
    sb.append("getData() with pattern ").append(coalesce(pattern)).append(" and values {");
    for (int i = 0; i < values.length; i++) {
        sb.append(" ").append(values[i]);
        if (i < values.length - 1) {
            sb.append(",");
...
voidassertFalse(boolean test, String message)
Throws an AssertionError if test is true.
if (test)
    throw new AssertionError(message);
voidassertFalse(final boolean result, final String message)
assert False
if (result)
    throw new IllegalArgumentException(message);
voidassertFalse(String string, boolean b)
assert False
if (b)
    throw new IllegalStateException(string);
voidassertFieldPositive(int fieldValue, String fieldName)
Throws an IllegalArgumentException if the specified field is <=0.
if (fieldValue <= 0)
    throw new IllegalArgumentException("Field '" + fieldName + "' must be a positive integer.");
voidassertGreater(long first, long second)
Assert that the first argument is greater than the second
if (first <= second) {
    throw new AssertionError(String.format("expected <%d> to be greater than <%d>", first, second));
voidassertGreaterOrEqualsThan(final long value, final long limit, final String name)
Asserts that the parameter's value is equals or greater than a specific limit.
if (value < limit) {
    throw new IllegalArgumentException(PREFIX + name + " is less than limit.");
voidassertGreaterThanOrEquals(String name, double comparedTo, double number)
assert Greater Than Or Equals
if (lessThan(comparedTo, number)) {
    throw new AssertionError(
            name + ": " + number + " is not greater than or equal to " + comparedTo + " !");
voidassertHasInterface(Class interfaceClass, Class objectClass)
assert Has Interface
Class<?>[] interfaces = objectClass.getInterfaces();
for (Class<?> singleInterface : interfaces) {
    if (singleInterface.equals(interfaceClass)) {
        return;
throw new AssertionError("Class " + objectClass.getName() + " did not implement interface: " + ""
        + interfaceClass.getName());
...
voidassertHasLength(String... params)
Check that string is not null
if (params != null) {
    for (int idx = 0; idx < params.length; idx++) {
        String currentparam = params[idx];
        if (null == currentparam || currentparam.isEmpty()) {
            throw new IllegalArgumentException(
                    "[Assertion failed] - Parameter #" + idx + "(string)  must not be null nor empty");