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

voidassertSame(Object targetObject0, Object targetObject1)
assert Same
System.out.println(targetObject0 == targetObject1);
voidassertSameClazz(Object object, Object defaults)
assert Same Clazz
if (!object.getClass().equals(defaults.getClass())) {
    throw new RuntimeException("Objects must have the same class: " + object.getClass().getName() + " != "
            + defaults.getClass().getName());
voidassertSameObject(Object obj1, Object obj2)
Checks object memory equality
if (obj1 != obj2) {
    throw new AssertionError("Objects are not the same");
voidassertSameSize(double[][] newLogPhi, double[][] logPhi)
assert Same Size
assert (newLogPhi.length == logPhi.length);
for (int k = 0; k < logPhi.length; k++) {
    assert (newLogPhi[k].length == logPhi[k].length);
voidassertSorted(final int[] values)
assert Sorted
int previousValue = values[0];
for (int i = 0; i < values.length; i++) {
    if (previousValue > values[i]) {
        String message = String.format("%d at index %d is smaller than its previous value %d", values[i], i,
                previousValue);
        throw new AssertionError(message);
String[]assertSplit(final String text, final int length)
assert Split
return assertSplit(text, length,
        "'" + text + "' must have at least " + length + " parts delimited by '.' or '::'.");
voidassertSquare(double[]... d)
assert Square
if (d.length > 2) {
    for (int i = 0; i < d.length; i++) {
        assertSquare(d[i]);
} else {
    int firstLength = d[0].length;
    for (int i = 1; i < d.length; i++) {
        assert d[i].length == firstLength;
...
voidassertState(boolean expression)
assert State
if (!expression) {
    throw new IllegalStateException();
voidassertStringMatch(String first, String second)
assert String Match
Exception ex = new Exception(first + "!=" + second);
if (first == null && second != null)
    throw ex;
if (second != null && first.equals(second) == false)
    throw ex;
voidassertStringNotEmpty(String str, String name)
Check if the given string is empty (trimmed).
if (str != null && str.trim().length() == 0) {
    throw new IllegalArgumentException(name + " should not be empty (trimmed).");