org.junit.internal.ExactComparisonCriteria Java Examples

The following examples show how to use org.junit.internal.ExactComparisonCriteria. 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);
    }
}
 
Example #2
Source File: Assert.java    From firebase-android-sdk with Apache License 2.0 2 votes vote down vote up
/**
 * Asserts that two object arrays are equal. If they are not, an {@link AssertionError} is thrown
 * with the given message. If <code>expecteds</code> and <code>actuals</code> are <code>null
 * </code>, they are considered equal.
 *
 * @param message the identifying message for the {@link AssertionError} (<code>null</code> okay)
 * @param expecteds Object array or array of arrays (multi-dimensional array) with expected
 *     values.
 * @param actuals Object array or array of arrays (multi-dimensional array) with actual values
 */
private static void internalArrayEquals(String message, Object expecteds, Object actuals)
    throws ArrayComparisonFailure {
  new ExactComparisonCriteria().arrayEquals(message, expecteds, actuals);
}
 
Example #3
Source File: Assert.java    From j2cl with Apache License 2.0 2 votes vote down vote up
/**
 * Asserts that two object arrays are equal. If they are not, an
 * {@link AssertionError} is thrown with the given message. If
 * <code>expecteds</code> and <code>actuals</code> are <code>null</code>,
 * they are considered equal.
 *
 * @param message the identifying message for the {@link AssertionError} (<code>null</code>
 * okay)
 * @param expecteds Object array or array of arrays (multi-dimensional array) with
 * expected values.
 * @param actuals Object array or array of arrays (multi-dimensional array) with
 * actual values
 */
private static void internalArrayEquals(String message, Object expecteds,
        Object actuals) throws ArrayComparisonFailure {
    new ExactComparisonCriteria().arrayEquals(message, expecteds, actuals);
}
 
Example #4
Source File: Assert.java    From Java-Thread-Affinity with Apache License 2.0 2 votes vote down vote up
/**
 * Asserts that two object arrays are equal. If they are not, an
 * {@link AssertionError} is thrown with the given message. If
 * <code>expecteds</code> and <code>actuals</code> are <code>null</code>,
 * they are considered equal.
 *
 * @param message   the identifying message for the {@link AssertionError} (<code>null</code>
 *                  okay)
 * @param expecteds Object array or array of arrays (multi-dimensional array) with
 *                  expected values.
 * @param actuals   Object array or array of arrays (multi-dimensional array) with
 *                  actual values
 */
private static void internalArrayEquals(String message, Object expecteds,
                                        Object actuals) throws ArrayComparisonFailure {
    new ExactComparisonCriteria().arrayEquals(message, expecteds, actuals);
}