Skip to content

Commit 796862e

Browse files
committed
Use deep comparison on Object2DArrayAssert#isDeepEqualTo() (fixes #1976)
1 parent 6b8696b commit 796862e

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/main/java/org/assertj/core/api/Object2DArrayAssert.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.assertj.core.error.array2d.Array2dElementShouldBeDeepEqual.elementShouldBeEqual;
1919

2020
import java.util.Comparator;
21+
import java.util.Objects;
2122

2223
import org.assertj.core.data.Index;
2324
import org.assertj.core.internal.Failures;
@@ -86,7 +87,7 @@ public Object2DArrayAssert<ELEMENT> isDeepEqualTo(ELEMENT[][] expected) {
8687
info.representation().toStringOf(actual), info.representation().toStringOf(expected));
8788
}
8889
for (int j = 0; j < actualSubArray.length; j++) {
89-
if (actualSubArray[j] != expectedSubArray[j]) {
90+
if (!Objects.deepEquals(actualSubArray[j], expectedSubArray[j])) {
9091
throw failures.failure(info, elementShouldBeEqual(actualSubArray[j], expectedSubArray[j], i, j),
9192
info.representation().toStringOf(actual), info.representation().toStringOf(expected));
9293
}

src/test/java/org/assertj/core/api/object2darray/Object2DArrayAssert_isDeepEqualTo_Test.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.assertj.core.api.Object2DArrayAssert;
2525
import org.assertj.core.error.ErrorMessageFactory;
26+
import org.assertj.core.test.Person;
2627
import org.junit.jupiter.api.DisplayName;
2728
import org.junit.jupiter.api.Test;
2829

@@ -53,14 +54,58 @@ void should_pass_if_both_actual_and_expected_are_same_arrays() {
5354
}
5455

5556
@Test
56-
void should_pass_if_both_actual_and_expected_are_equal() {
57+
void should_pass_if_both_actual_and_expected_have_same_references() {
5758
// GIVEN
5859
String[][] actual = new String[][] { { "1", "2" }, { "3" }, { "4", "5", "6" } };
5960
String[][] expected = new String[][] { { "1", "2" }, { "3" }, { "4", "5", "6" } };
6061
// WHEN/THEN
6162
then(actual).isDeepEqualTo(expected);
6263
}
6364

65+
@Test
66+
void should_pass_if_both_actual_and_expected_are_equal() {
67+
// GIVEN
68+
Person[][] actual = new Person[][] {
69+
{ new Person("Homer"), new Person("Marge") },
70+
{ new Person("Liza"), new Person("Bart"), new Person("Maggie") },
71+
{ null, null }
72+
};
73+
Person[][] expected = new Person[][] {
74+
{ new Person("Homer"), new Person("Marge") },
75+
{ new Person("Liza"), new Person("Bart"), new Person("Maggie") },
76+
{ null, null }
77+
};
78+
// WHEN/THEN
79+
then(actual).isDeepEqualTo(expected);
80+
}
81+
82+
@Test
83+
void should_pass_with_three_dimensional_equal_arrays() {
84+
// GIVEN
85+
Person[][][] actual = new Person[][][] {
86+
{
87+
{ new Person("Homer"), new Person("Marge") },
88+
{ new Person("Liza"), new Person("Bart"), new Person("Maggie") },
89+
{ null, null }
90+
},
91+
{
92+
{ new Person("Apu"), new Person("Ned"), new Person("Milhouse") }
93+
},
94+
};
95+
Person[][][] expected = new Person[][][] {
96+
{
97+
{ new Person("Homer"), new Person("Marge") },
98+
{ new Person("Liza"), new Person("Bart"), new Person("Maggie") },
99+
{ null, null }
100+
},
101+
{
102+
{ new Person("Apu"), new Person("Ned"), new Person("Milhouse") }
103+
},
104+
};
105+
// WHEN/THEN
106+
then(actual).isDeepEqualTo(expected);
107+
}
108+
64109
@Test
65110
void should_fail_if_actual_is_null() {
66111
// GIVEN

0 commit comments

Comments
 (0)