Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing collection using equals method for assertEquals #2460

Merged
merged 5 commits into from Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
Current
Fixed: GITHUB-2296: assertEquals doesn't work for sets as order is not guaranteed. (Prashant Maroti)
Fixed: GITHUB-1632: throwing SkipException sets iTestResult status to Failure instead of Skip (Julien Herr & Krishnan Mahadevan)
New : GITHUB-2456: Add onDataProviderFailure listener (Krishnan Mahadevan)
Fixed: GITHUB-2445: NPE in FailedReporter.java With Tests Created in Factory (Arham Jain)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/testng/Assert.java
Expand Up @@ -12,6 +12,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.testng.collections.Lists;

Expand Down Expand Up @@ -1074,7 +1075,7 @@ public static void assertEquals(Collection<?> actual, Collection<?> expected) {
* @param message the assertion error message
*/
public static void assertEquals(Collection<?> actual, Collection<?> expected, String message) {
if (actual == expected) {
if (Objects.equals(actual, expected)) {
return;
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/testng/AssertTest.java
Expand Up @@ -41,6 +41,13 @@ public void nullSetAssertEquals() {
Assert.assertEquals(actual, expected);
}

@Test
public void testSetAssertEquals() {
This conversation was marked as resolved.
Show resolved Hide resolved
final Collection expected = Sets.newHashSet(new Asymmetric(10, 'a'), new Asymmetric(11, 'b'));
final Collection actual = Sets.newHashSet(new Asymmetric(11, 'b'), new Asymmetric(10, 'a'));
Assert.assertEquals(actual, expected);
}

@Test
public void nullMapAssertEquals() {
Map expected = null;
Expand Down