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

voidassertNotTrue(boolean conditionThatMustNotBeTrue, String msgWhenTrue)
assert Not True
if (conditionThatMustNotBeTrue) {
    throw new IllegalArgumentException(msgWhenTrue);
voidassertNotTrue(boolean value, String message)
Throws exception if value is true.
if (value == true) {
    throw new IllegalArgumentException(message);
booleanassertObjectEmpty(Object value)
assert Object Empty
return value != null;
voidassertObjEquals(Object expected, Object actual)
assert Obj Equals
assertWithMessage(null, expected, actual);
voidassertOffsetLengthValid(int offset, int length, int arrayLength)
assert Offset Length Valid
if (offset < 0) {
    throw new IllegalArgumentException("The array offset was negative");
if (length < 0) {
    throw new IllegalArgumentException("The array length was negative");
if (offset + length > arrayLength) {
    throw new ArrayIndexOutOfBoundsException("The array offset+length would access past end of array");
...
voidassertOid(final String s)
assert Oid
if ((s != null) && !isOid(s)) {
    throw new RuntimeException("Expected an OID but found " + s);
voidassertOneBitMask(long mask)
assert One Bit Mask
assert (mask & (mask - 1)) == 0 : "Mask must have only one bit set, but got: " + Long.toBinaryString(mask);
ObjectassertParameter(Class expectedClass, Object[] params, int index)
Utility method to provide more descriptive unchecked exceptions for unmarshalling object from Tapestry service Parameters.
if (params == null || params.length < index) {
    throw new IllegalArgumentException("Missing parameter at position " + index);
if (params[index] != null) {
    Class actualClass = params[index].getClass();
    if (!expectedClass.isAssignableFrom(actualClass)) {
        throw new IllegalArgumentException("Object of class type " + expectedClass.getName()
                + " was expected at position " + index + " but class type was " + actualClass.getName());
...
voidassertParameterInRange(long param, long lower, long upper)
assert Parameter In Range
if (!checkParamRange(param, lower, true, upper, true)) {
    throw new IllegalArgumentException(
            String.format("%d not in valid range [%d, %d]", param, lower, upper));
voidassertParameterWithinBounds(String name, long lower, long upper, long parameter)
Throw an IllegalArgumentException when a number is not within the supplied range.
if (parameter < lower || parameter > upper) {
    throw new IllegalArgumentException(
            String.format("Invalid %s: %d (expected: %d <= n < %d)", name, parameter, lower, upper + 1));