diff --git a/src/main/java/org/assertj/core/api/Object2DArrayAssert.java b/src/main/java/org/assertj/core/api/Object2DArrayAssert.java index 263deadcbd8..f7ee228d705 100644 --- a/src/main/java/org/assertj/core/api/Object2DArrayAssert.java +++ b/src/main/java/org/assertj/core/api/Object2DArrayAssert.java @@ -18,6 +18,7 @@ import static org.assertj.core.error.array2d.Array2dElementShouldBeDeepEqual.elementShouldBeEqual; import java.util.Comparator; +import java.util.Objects; import org.assertj.core.data.Index; import org.assertj.core.internal.Failures; @@ -86,7 +87,7 @@ public Object2DArrayAssert isDeepEqualTo(ELEMENT[][] expected) { info.representation().toStringOf(actual), info.representation().toStringOf(expected)); } for (int j = 0; j < actualSubArray.length; j++) { - if (actualSubArray[j] != expectedSubArray[j]) { + if (!Objects.deepEquals(actualSubArray[j], expectedSubArray[j])) { throw failures.failure(info, elementShouldBeEqual(actualSubArray[j], expectedSubArray[j], i, j), info.representation().toStringOf(actual), info.representation().toStringOf(expected)); } diff --git a/src/test/java/org/assertj/core/api/object2darray/Object2DArrayAssert_isDeepEqualTo_Test.java b/src/test/java/org/assertj/core/api/object2darray/Object2DArrayAssert_isDeepEqualTo_Test.java index d4a2e036a9d..6e2ef348b3a 100644 --- a/src/test/java/org/assertj/core/api/object2darray/Object2DArrayAssert_isDeepEqualTo_Test.java +++ b/src/test/java/org/assertj/core/api/object2darray/Object2DArrayAssert_isDeepEqualTo_Test.java @@ -23,6 +23,7 @@ import org.assertj.core.api.Object2DArrayAssert; import org.assertj.core.error.ErrorMessageFactory; +import org.assertj.core.test.Person; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -53,7 +54,7 @@ void should_pass_if_both_actual_and_expected_are_same_arrays() { } @Test - void should_pass_if_both_actual_and_expected_are_equal() { + void should_pass_if_both_actual_and_expected_have_same_references() { // GIVEN String[][] actual = new String[][] { { "1", "2" }, { "3" }, { "4", "5", "6" } }; String[][] expected = new String[][] { { "1", "2" }, { "3" }, { "4", "5", "6" } }; @@ -61,6 +62,50 @@ void should_pass_if_both_actual_and_expected_are_equal() { then(actual).isDeepEqualTo(expected); } + @Test + void should_pass_if_both_actual_and_expected_are_equal() { + // GIVEN + Person[][] actual = new Person[][] { + { new Person("Homer"), new Person("Marge") }, + { new Person("Liza"), new Person("Bart"), new Person("Maggie") }, + { null, null } + }; + Person[][] expected = new Person[][] { + { new Person("Homer"), new Person("Marge") }, + { new Person("Liza"), new Person("Bart"), new Person("Maggie") }, + { null, null } + }; + // WHEN/THEN + then(actual).isDeepEqualTo(expected); + } + + @Test + void should_pass_with_three_dimensional_equal_arrays() { + // GIVEN + Person[][][] actual = new Person[][][] { + { + { new Person("Homer"), new Person("Marge") }, + { new Person("Liza"), new Person("Bart"), new Person("Maggie") }, + { null, null } + }, + { + { new Person("Apu"), new Person("Ned"), new Person("Milhouse") } + }, + }; + Person[][][] expected = new Person[][][] { + { + { new Person("Homer"), new Person("Marge") }, + { new Person("Liza"), new Person("Bart"), new Person("Maggie") }, + { null, null } + }, + { + { new Person("Apu"), new Person("Ned"), new Person("Milhouse") } + }, + }; + // WHEN/THEN + then(actual).isDeepEqualTo(expected); + } + @Test void should_fail_if_actual_is_null() { // GIVEN