Skip to content

Commit 573607b

Browse files
assertEquals(Set,Set) now ignores ordering as it did before #2643
1 parent 49dbdc9 commit 573607b

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Current
2+
Fixed: GITHUB-2643: assertEquals(Set,Set) now ignores ordering as it did before. (Elis Edlund)
23
Fixed: GITHUB-2653: Assert methods requires casting since TestNg 7.0 for mixed boxed and unboxed primitives in assertEquals.
34
Fixed: GITHUB-2229: Restore @BeforeGroups and @AfterGroups Annotations functionality (Krishnan Mahadevan)
45
Fixed: GITHUB-2563: Skip test if its data provider provides no data (Krishnan Mahadevan)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ private static String getNotEqualReason(Iterator<?> actual, Iterator<?> expected
17951795
}
17961796

17971797
private static String getNotEqualReason(Set<?> actual, Set<?> expected) {
1798-
if (actual == expected) { // We don't use Arrays.equals here because order is checked
1798+
if (actual == expected) {
17991799
return null;
18001800
}
18011801

@@ -1807,7 +1807,7 @@ private static String getNotEqualReason(Set<?> actual, Set<?> expected) {
18071807
if (!Objects.equals(actual, expected)) {
18081808
return "Sets differ: expected " + expected + " but got " + actual;
18091809
}
1810-
return getNotEqualReason(actual.iterator(), expected.iterator());
1810+
return null;
18111811
}
18121812

18131813
/**

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

+24-6
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ public void checkIteratorNotEqualsFailsWhenDifferentOrder() {
373373
assertNotEquals(iterator1, iterator2);
374374
}
375375

376-
@Test(description = "GITHUB-2540", expectedExceptions = AssertionError.class)
377-
public void checkSetEqualsFailsWhenDifferentOrder() {
376+
@Test(description = "GITHUB-2643")
377+
public void checkSetEqualsWhenDifferentOrder() {
378378

379379
Set<String> set1 = new LinkedHashSet<>(Arrays.asList("a", "b", "c"));
380380
Set<String> set2 = new LinkedHashSet<>(Arrays.asList("a", "c", "b"));
@@ -400,24 +400,42 @@ public void checkSetEquals() {
400400
assertEquals(set1, set2);
401401
}
402402

403-
@Test(description = "GITHUB-2540")
404-
public void checkSetNotEquals() {
403+
@Test(description = "GITHUB-2643", expectedExceptions = AssertionError.class)
404+
public void checkSetNotEqualsFailsWhenDifferentOrder() {
405405

406406
Set<String> set1 = new LinkedHashSet<>(Arrays.asList("a", "b", "c"));
407407
Set<String> set2 = new LinkedHashSet<>(Arrays.asList("a", "c", "b"));
408408

409409
assertNotEquals(set1, set2);
410410
}
411411

412-
@Test(description = "GITHUB-2540", expectedExceptions = AssertionError.class)
413-
public void checkSetNotEqualsFailsWhenDifferentOrder() {
412+
@Test(description = "GITHUB-2643", expectedExceptions = AssertionError.class)
413+
public void checkSetNotEqualsFailsWhenSameOrder() {
414414

415415
Set<String> set1 = new LinkedHashSet<>(Arrays.asList("a", "b", "c"));
416416
Set<String> set2 = new LinkedHashSet<>(Arrays.asList("a", "b", "c"));
417417

418418
assertNotEquals(set1, set2);
419419
}
420420

421+
@Test(description = "GITHUB-2643")
422+
public void checkSetNotEqualsWhenNotSameSets() {
423+
424+
Set<String> set1 = new LinkedHashSet<>(Arrays.asList("a", "b"));
425+
Set<String> set2 = new LinkedHashSet<>(Arrays.asList("a", "b", "c"));
426+
427+
assertNotEquals(set1, set2);
428+
}
429+
430+
@Test(description = "GITHUB-2643", expectedExceptions = AssertionError.class)
431+
public void checkSetEqualsFailsWhenNotSameSets() {
432+
433+
Set<String> set1 = new LinkedHashSet<>(Arrays.asList("a", "b", "c"));
434+
Set<String> set2 = new LinkedHashSet<>(Arrays.asList("a", "b"));
435+
436+
assertEquals(set1, set2);
437+
}
438+
421439
@Test(description = "GITHUB-2540", expectedExceptions = AssertionError.class)
422440
public void checkArrayEqualsFailsWhenDifferentOrder() {
423441

0 commit comments

Comments
 (0)