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

voidassertNotBlank(final String arg, final String message)
Throws an IllegalArgumentException with the given message if null or blank.
if (arg == null) {
    throw new IllegalArgumentException("Null argument not allowed: " + message);
if (arg.trim().equals("")) {
    throw new IllegalArgumentException("Blank argument not allowed: " + message);
StringassertNotBlank(final String value, final String exceptionMessage)
Assert that the given value is not blank.
if (notBlank(value)) {
    return value;
throw new IllegalArgumentException(exceptionMessage);
booleanassertNotBlank(final String... strings)
assert Not Blank
for (String s : strings) {
    if (s == null || s.trim().isEmpty())
        return false;
return true;
voidassertNotBlankOrThrowException(final String... strings)
assert Not Blank Or Throw Exception
if (!assertNotBlank(strings))
    throw new IllegalArgumentException("Cannot be blank ! (null or empty)");
booleanassertNotEmpty(final String str)
assert Not Empty
return null != str && !str.isEmpty();
voidassertNotEmpty(String string, String exceptionMessageTitle)
assert Not Empty
if (isNullOrEmpty(string)) {
    throw new IllegalArgumentException(exceptionMessageTitle + " cannot be null or empty string");
voidassertNotEmpty(String value, String message)
assert Not Empty
if (value == null || "".equals(value)) {
    throw new IllegalArgumentException(message);
voidassertNotEmptyString(final String s)
assert Not Empty String
if ("".equals(s)) {
    throw new IllegalArgumentException("Method parameter cannot be empty string");
voidassertNotEquals(final Object actual, final Object expected, final String name)
Asserts that two parameters don't have the same value.
if (actual == null) {
    if (expected == null) {
        throw new IllegalArgumentException(PREFIX + name + " is equals the expected one.");
} else {
    if (actual.equals(expected)) {
        throw new IllegalArgumentException(PREFIX + name + " is equals the expected one.");
voidassertNotMatches(String name, String regExp, String actual)
assert Not Matches
if (matches(regExp, actual)) {
    throw new AssertionError(name + ": " + actual + " is matching " + regExp + " when it shouldn't!");