diff --git a/CHANGES.txt b/CHANGES.txt index 28dac6f4e..36d4b7bd6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,7 @@ Current (7.11.0) Fixed: GITHUB-3028: Execution stalls when using "use-global-thread-pool" (Krishnan Mahadevan) Fixed: GITHUB-3122: Update JCommander to 1.83 (Antoine Dessaigne) +Fixed: GITHUB-3135: assertEquals on arrays - Failure message is missing information about the array index when an array element is unexpectedly null or non-null (Albert Choi) 7.10.2 Fixed: GITHUB-3117: ListenerComparator doesn't work (Krishnan Mahadevan) diff --git a/testng-asserts/src/main/java/org/testng/Assert.java b/testng-asserts/src/main/java/org/testng/Assert.java index 0adfef23d..ec1d6dd0d 100644 --- a/testng-asserts/src/main/java/org/testng/Assert.java +++ b/testng-asserts/src/main/java/org/testng/Assert.java @@ -1780,7 +1780,7 @@ public static void assertEquals(Object[] actual, Object[] expected, String messa continue; } if ((a == null && e != null) || (a != null && e == null)) { - failNotEquals(a, e, message); + failNotEquals(a, e, errorMessage); } // Compare by value for multi-dimensional array. if (e.getClass().isArray()) { diff --git a/testng-asserts/src/test/java/org/testng/AssertTest.java b/testng-asserts/src/test/java/org/testng/AssertTest.java index 9034a5a50..582fcc558 100644 --- a/testng-asserts/src/test/java/org/testng/AssertTest.java +++ b/testng-asserts/src/test/java/org/testng/AssertTest.java @@ -355,6 +355,33 @@ public void testInequalityMessage() { Assert.assertEquals("x", "y"); } + @Test( + description = "GITHUB-3135", + expectedExceptions = AssertionError.class, + expectedExceptionsMessageRegExp = + "Arrays differ at element \\[2\\]: 3 != 5 expected \\[3\\] but found \\[5\\]") + public void testAssertEqualsArrayElementDiffers() { + Assert.assertEquals(new Integer[] {1, 2, 5}, new Integer[] {1, 2, 3}); + } + + @Test( + description = "GITHUB-3135", + expectedExceptions = AssertionError.class, + expectedExceptionsMessageRegExp = + "Arrays differ at element \\[2\\]: 3 != null expected \\[3\\] but found \\[null\\]") + public void testAssertEqualsArrayElementIsNull() { + Assert.assertEquals(new Integer[] {1, 2, null}, new Integer[] {1, 2, 3}); + } + + @Test( + description = "GITHUB-3135", + expectedExceptions = AssertionError.class, + expectedExceptionsMessageRegExp = + "Arrays differ at element \\[2\\]: null != 5 expected \\[null\\] but found \\[5\\]") + public void testAssertEqualsArrayElementIsNotNull() { + Assert.assertEquals(new Integer[] {1, 2, 5}, new Integer[] {1, 2, null}); + } + @Test public void testAssertEqualsNoOrder() { String[] actual = {"a", "b"};