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

voidassertLongPositive(long val, String name)
Check if the given long value is positive.
if (val <= 0) {
    throw new IllegalArgumentException(name + " [" + val + "] should be positive.");
voidassertMandatoryParameter(boolean assertion, String parameterName)
assert Mandatory Parameter
if (!assertion) {
    throw new IllegalArgumentException(parameterName + " must be set");
voidassertMatches(String name, String regExp, String actual)
assert Matches
if (notMatches(regExp, actual)) {
    throw new AssertionError(name + ": " + actual + " is not matching " + regExp + "!");
voidassertMergeTestPostcondition(double[] arr, long[] brr, int arrLen)
assert Merge Test Postcondition
int violationsCount = 0;
for (int i = 0; i < arrLen - 1; i++) {
    if (arr[i] > arr[i + 1]) {
        violationsCount++;
for (int i = 0; i < arrLen; i++) {
    if (brr[i] != (long) (1e12 * (1.0 - arr[i])))
...
voidassertMessageEquals(Throwable ex, String msg)
assert Message Equals
if (!msg.equals(ex.getMessage())) {
    throw new AssertionError(
            "Exception message should be [" + msg + "], but was [" + ex.getMessage() + "].");
StringassertNonEmpty(String s, String name)
assert Non Empty
if (s == null || s.length() == 0) {
    throw new IllegalArgumentException(name + " must not be null or empty");
return s;
voidassertNonFatal(boolean test, String msg)
assert Non Fatal
if (!test) {
    Exception e = new Exception(msg);
    e.printStackTrace(System.out);
voidassertNonNegative(int field, String fieldName)
assert Non Negative
if (field < 0) {
    throw new IllegalArgumentException(fieldName + " must be equal to or greater than zero");
voidassertNonZero(int i, String fieldName)
assert Non Zero
if (i == 0) {
    throw new IllegalArgumentException(fieldName + " must be non-zero");
StringassertNoSlash(final String ofString)
assert No Slash
if (!ofString.endsWith("/")) {
    return ofString;
return ofString.substring(0, ofString.length() - 1);