Skip to content

Commit

Permalink
assertEquals(Set,Set) now ignores ordering as it did before testng-te…
Browse files Browse the repository at this point in the history
  • Loading branch information
Elisedlund-ericsson committed Oct 28, 2021
1 parent 49dbdc9 commit 573607b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
Current
Fixed: GITHUB-2643: assertEquals(Set,Set) now ignores ordering as it did before. (Elis Edlund)
Fixed: GITHUB-2653: Assert methods requires casting since TestNg 7.0 for mixed boxed and unboxed primitives in assertEquals.
Fixed: GITHUB-2229: Restore @BeforeGroups and @AfterGroups Annotations functionality (Krishnan Mahadevan)
Fixed: GITHUB-2563: Skip test if its data provider provides no data (Krishnan Mahadevan)
Expand Down
4 changes: 2 additions & 2 deletions testng-asserts/src/main/java/org/testng/Assert.java
Expand Up @@ -1795,7 +1795,7 @@ private static String getNotEqualReason(Iterator<?> actual, Iterator<?> expected
}

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

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

/**
Expand Down
30 changes: 24 additions & 6 deletions testng-asserts/src/test/java/test/asserttests/AssertTest.java
Expand Up @@ -373,8 +373,8 @@ public void checkIteratorNotEqualsFailsWhenDifferentOrder() {
assertNotEquals(iterator1, iterator2);
}

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

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

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

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

assertNotEquals(set1, set2);
}

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

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

assertNotEquals(set1, set2);
}

@Test(description = "GITHUB-2643")
public void checkSetNotEqualsWhenNotSameSets() {

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

assertNotEquals(set1, set2);
}

@Test(description = "GITHUB-2643", expectedExceptions = AssertionError.class)
public void checkSetEqualsFailsWhenNotSameSets() {

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

assertEquals(set1, set2);
}

@Test(description = "GITHUB-2540", expectedExceptions = AssertionError.class)
public void checkArrayEqualsFailsWhenDifferentOrder() {

Expand Down

0 comments on commit 573607b

Please sign in to comment.