org.junit.internal.ComparisonCriteria Java Examples

The following examples show how to use org.junit.internal.ComparisonCriteria. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraalTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compares two given values for equality, doing a recursive test if both values are arrays of
 * the same type.
 *
 * @param message the identifying message for the {@link AssertionError}
 * @param delta the maximum delta between two doubles or floats for which both numbers are still
 *            considered equal.
 */
protected void assertDeepEquals(String message, Object expected, Object actual, double delta) {
    if (expected != null && actual != null) {
        Class<?> expectedClass = expected.getClass();
        Class<?> actualClass = actual.getClass();
        if (expectedClass.isArray()) {
            Assert.assertTrue(message, expected != null);
            Assert.assertTrue(message, actual != null);
            Assert.assertEquals(message, expectedClass, actual.getClass());
            if (expected instanceof int[]) {
                Assert.assertArrayEquals(message, (int[]) expected, (int[]) actual);
            } else if (expected instanceof byte[]) {
                Assert.assertArrayEquals(message, (byte[]) expected, (byte[]) actual);
            } else if (expected instanceof char[]) {
                Assert.assertArrayEquals(message, (char[]) expected, (char[]) actual);
            } else if (expected instanceof short[]) {
                Assert.assertArrayEquals(message, (short[]) expected, (short[]) actual);
            } else if (expected instanceof float[]) {
                Assert.assertArrayEquals(message, (float[]) expected, (float[]) actual, (float) delta);
            } else if (expected instanceof long[]) {
                Assert.assertArrayEquals(message, (long[]) expected, (long[]) actual);
            } else if (expected instanceof double[]) {
                Assert.assertArrayEquals(message, (double[]) expected, (double[]) actual, delta);
            } else if (expected instanceof boolean[]) {
                new ExactComparisonCriteria().arrayEquals(message, expected, actual);
            } else if (expected instanceof Object[]) {
                new ComparisonCriteria() {
                    @Override
                    protected void assertElementsEqual(Object e, Object a) {
                        assertDeepEquals(message, e, a, delta);
                    }
                }.arrayEquals(message, expected, actual);
            } else {
                Assert.fail((message == null ? "" : message) + "non-array value encountered: " + expected);
            }
        } else if (expectedClass.equals(double.class) && actualClass.equals(double.class)) {
            Assert.assertEquals((double) expected, (double) actual, delta);
        } else if (expectedClass.equals(float.class) && actualClass.equals(float.class)) {
            Assert.assertEquals((float) expected, (float) actual, delta);
        } else {
            Assert.assertEquals(message, expected, actual);
        }
    } else {
        Assert.assertEquals(message, expected, actual);
    }
}