Java Utililty Methods Assert Equal

List of utility methods to do Assert Equal

Description

The list of methods to do Assert Equal are organized into topic(s).

Method

voidassertEquals(double x, double y)
assert Equals
assertEquals(x, y, 1e-10);
voidassertEquals(final int expected, final int actual)
assert Equals
if (expected != actual) {
    throw new AssertionError("expected <" + expected + ">, but was <" + actual + ">");
voidassertEquals(final Object actual, final Object expected, final String name)
Asserts that two parameters have the same value.
if (actual == null) {
    if (expected != null) {
        throw new IllegalArgumentException(PREFIX + name + " is not equals the expected one.");
} else {
    if (!actual.equals(expected)) {
        throw new IllegalArgumentException(PREFIX + name + " is not equals the expected one.");
voidassertEquals(float a1, float a2)
Ensure that the two values given are equal, if not fail the test
if (a1 != a2) {
    throw new RuntimeException("TEST FAILS: " + a1 + " should be " + a2);
voidassertEquals(int a, int b)
assert Equals
if (a != b) {
    fail("assertionFailed");
voidassertEquals(int i1, int i2)
Throws a runtime exception if i1 != i2.
if (i1 != i2) {
    throw new RuntimeException("assert " + i1 + " == " + i2);
voidassertEquals(Integer a, Integer b)
assert Equals
if (!a.equals(b))
    throw new AssertionError();
voidassertEquals(Object a, Object b, String msg)
assert Equals
if (a == b) {
    return;
if (a != null && a.equals(b)) {
    return;
throw new AssertionError(msg + " expecting: " + b + " actual: " + a);
voidassertEquals(Object exp, Object actual)
assert Equals
if (!(exp.equals(actual))) {
    throw new Exception("Expected #" + exp + "# but was #" + actual + "#");
voidassertEquals(Object expected, Object actual)
assert Equals
assertEquals(null, expected, actual);