Skip to content

Commit 2df6a79

Browse files
author
Victor Uria Valle
committed
Fix assertEqualsDeep wrong comparison and add method without message (refs #3140)
1 parent d1a96af commit 2df6a79

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Current (7.11.0)
22
Fixed: GITHUB-3028: Execution stalls when using "use-global-thread-pool" (Krishnan Mahadevan)
33
Fixed: GITHUB-3122: Update JCommander to 1.83 (Antoine Dessaigne)
44
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)
5+
Fixed: GITHUB-3140: assertEqualsDeep on Sets - Deep comparison was using the wrong expected value
56

67
7.10.2
78
Fixed: GITHUB-3117: ListenerComparator doesn't work (Krishnan Mahadevan)

testng-asserts/src/main/java/org/testng/Assert.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2067,14 +2067,18 @@ private static String getNotEqualDeepReason(Set<?> actual, Set<?> expected) {
20672067
return arrayNotEqualReason;
20682068
}
20692069
} else {
2070-
if (!areEqualImpl(value, expected)) {
2070+
if (!areEqualImpl(value, expectedValue)) {
20712071
return "Sets not equal: expected: " + expectedValue + " and actual: " + value;
20722072
}
20732073
}
20742074
}
20752075
return null;
20762076
}
20772077

2078+
public static void assertEqualsDeep(Set<?> actual, Set<?> expected) {
2079+
assertEqualsDeep(actual, expected, null);
2080+
}
2081+
20782082
public static void assertEqualsDeep(Set<?> actual, Set<?> expected, String message) {
20792083
String notEqualDeepReason = getNotEqualDeepReason(actual, expected);
20802084
if (notEqualDeepReason != null) {

testng-asserts/src/test/java/org/testng/AssertTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,28 @@ public void testAssertNotEqualsWithNull() {
580580
Assert.assertNotEquals(obj, obj);
581581
}
582582

583+
@Test(description = "GITHUB-3140")
584+
public void testAssertEqualsDeepSet() {
585+
var expectedSet = new HashSet<>();
586+
expectedSet.add(new Contrived(1));
587+
expectedSet.add(new Contrived[] {new Contrived(1)});
588+
var actualSet = new HashSet<>();
589+
actualSet.add(new Contrived(1));
590+
actualSet.add(new Contrived[] {new Contrived(1)});
591+
Assert.assertEqualsDeep(actualSet, expectedSet);
592+
}
593+
594+
@Test(description = "GITHUB-3140", expectedExceptions = AssertionError.class)
595+
public void testAssertEqualsDeepSetFail() {
596+
var expectedSet = new HashSet<>();
597+
expectedSet.add(new Contrived(1));
598+
expectedSet.add(new Contrived[] {new Contrived(1)});
599+
var actualSet = new HashSet<>();
600+
actualSet.add(new Contrived(1));
601+
actualSet.add(new Contrived[] {new Contrived(2)});
602+
Assert.assertEqualsDeep(actualSet, expectedSet);
603+
}
604+
583605
static class Contrived {
584606

585607
int integer;

0 commit comments

Comments
 (0)