in src/main/java/org/junit/internal/ComparisonCriteria.java [31:92]
private void arrayEquals(String message, Object expecteds, Object actuals, boolean outer)
throws ArrayComparisonFailure {
if (expecteds == actuals
|| Arrays.deepEquals(new Object[] {expecteds}, new Object[] {actuals})) {
// The reflection-based loop below is potentially very slow, especially for primitive
// arrays. The deepEquals check allows us to circumvent it in the usual case where
// the arrays are exactly equal.
return;
}
String header = message == null ? "" : message + ": ";
// Only include the user-provided message in the outer exception.
String exceptionMessage = outer ? header : "";
if (expecteds == null) {
Assert.fail(exceptionMessage + "expected array was null");
}
if (actuals == null) {
Assert.fail(exceptionMessage + "actual array was null");
}
int actualsLength = Array.getLength(actuals);
int expectedsLength = Array.getLength(expecteds);
if (actualsLength != expectedsLength) {
header += "array lengths differed, expected.length="
+ expectedsLength + " actual.length=" + actualsLength + "; ";
}
int prefixLength = Math.min(actualsLength, expectedsLength);
for (int i = 0; i < prefixLength; i++) {
Object expected = Array.get(expecteds, i);
Object actual = Array.get(actuals, i);
if (isArray(expected) && isArray(actual)) {
try {
arrayEquals(message, expected, actual, false);
} catch (ArrayComparisonFailure e) {
e.addDimension(i);
throw e;
} catch (AssertionError e) {
// Array lengths differed.
throw new ArrayComparisonFailure(header, e, i);
}
} else {
try {
assertElementsEqual(expected, actual);
} catch (AssertionError e) {
throw new ArrayComparisonFailure(header, e, i);
}
}
}
if (actualsLength != expectedsLength) {
Object expected = getToStringableArrayElement(expecteds, expectedsLength, prefixLength);
Object actual = getToStringableArrayElement(actuals, actualsLength, prefixLength);
try {
Assert.assertEquals(expected, actual);
} catch (AssertionError e) {
throw new ArrayComparisonFailure(header, e, prefixLength);
}
}
}