/** * 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.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); } }