-
Notifications
You must be signed in to change notification settings - Fork 1k
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
GitHub 2913 #2914
GitHub 2913 #2914
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -563,4 +563,92 @@ public void checkArrayNotEqualsFailsWhenDifferentOrder() { | |
|
||
assertNotEquals(array1, array2); | ||
} | ||
|
||
@Test | ||
public void checkMapEquals() { | ||
Map<String, Object> map1 = new LinkedHashMap<>(); | ||
map1.put("a", "1"); | ||
map1.put("b", 2); | ||
Map<String, Object> map2 = new LinkedHashMap<>(); | ||
map2.put("b", 2); | ||
map2.put("a", "1"); | ||
|
||
assertMapsEqual(map1, map2); | ||
} | ||
|
||
@Test | ||
public void checkMapNotEquals() { | ||
Map<String, Object> map1 = new LinkedHashMap<>(); | ||
map1.put("a", "1"); | ||
map1.put("b", "2"); | ||
Map<String, Object> map2 = new LinkedHashMap<>(); | ||
map2.put("a", "1"); | ||
map2.put("b", 2); | ||
|
||
assertMapsNotEqual(map1, map2); | ||
} | ||
|
||
@Test(description = "GITHUB-2913") | ||
public void checkMapNotEqualsWithNull() { | ||
Map<String, Object> map1 = new LinkedHashMap<>(); | ||
map1.put("a", 1); | ||
map1.put("b", null); | ||
Map<String, Object> map2 = new LinkedHashMap<>(); | ||
map2.put("a", 1); | ||
map2.put("c", null); | ||
|
||
assertMapsNotEqual(map1, map2); | ||
} | ||
|
||
protected void assertMapsEqual(Map m1, Map m2) { | ||
assertEquals((Object) m1, (Object) m2); | ||
assertEquals(m1, m2); | ||
|
||
boolean succeeded = false; | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we refactor this to
This will do away with the extra variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the var name instead of the comment -- I've called it However putting the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (gradle insists on putting a newline between the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can try There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ahgittin - Sigh! my bad. Yes you are correct. |
||
assertNotEquals((Object) m1, (Object) m2); | ||
succeeded = true; | ||
} catch (AssertionError e) { | ||
/* expected */ | ||
} | ||
if (succeeded) { | ||
Assert.fail("Maps reported as not equal when equal: " + m1 + " / " + m2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be replaced but assertFalse |
||
} | ||
|
||
try { | ||
assertNotEquals(m1, m2); | ||
succeeded = true; | ||
} catch (AssertionError e) { | ||
/* expected */ | ||
} | ||
if (succeeded) { | ||
Assert.fail("Maps reported as not equal when equal: " + m1 + " / " + m2); | ||
} | ||
} | ||
|
||
protected void assertMapsNotEqual(Map m1, Map m2) { | ||
boolean succeeded = false; | ||
try { | ||
assertEquals((Object) m1, (Object) m2); | ||
succeeded = true; | ||
} catch (AssertionError e) { | ||
/* expected */ | ||
} | ||
if (succeeded) { | ||
Assert.fail("Maps reported as equal when not equal: " + m1 + " / " + m2); | ||
} | ||
|
||
try { | ||
assertEquals(m1, m2); | ||
succeeded = true; | ||
} catch (AssertionError e) { | ||
/* expected */ | ||
} | ||
if (succeeded) { | ||
Assert.fail("Maps reported as equal when not equal: " + m1 + " / " + m2); | ||
} | ||
|
||
assertNotEquals((Object) m1, (Object) m2); | ||
assertNotEquals(m1, m2); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahgittin It would be good if you could please help add your ID/name at the end of this line, so that we can call out your contribution in the release notes of this version (when it goes out). Its our small way of thanking you for helping TestNG become better.