Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: FEST-Assert 1.2
-
Fix Version/s: FEST-Assert 1.3
-
Component/s: Assert
-
Labels:None
-
Number of attachments :
Description
Just found what I consider to be a bug in MapAssert#containsEntry, the
current code ( 1.2 ):
private boolean containsEntry(Entry e) { if (e == null) throw new NullPointerException(formattedErrorMessage("Entries to check should not contain null")); if (!actual.containsKey(e.key)) return false; return actual.containsValue(e.value); }
Given entry e, the code asserts that the key exists, and that the
value exists. However, it's not asserting that the value the key
points to matches the value passed it.
Thus, a map containing:
1 : foo
2 : bar
will pass when called with: assertThat(map).includes(entry(1,bar));
Changing it to:
private boolean containsEntry(Entry e) { if (e == null) throw new NullPointerException(formattedErrorMessage("Entries to check should not contain null")); if (!actual.containsKey(e.key)) return false; return actual.get(e.key).equals(e.value); }
should suffice.