Asserts that the given Map contains the given entries, in any order. @param info contains information about the assertion. @param actual the given Map. @param entries the entries that are expected to be in the given Map. @throws NullPointerException if the array of entries i
(AssertionInfo info, Map<K, V> actual, MapEntry<? extends K, ? extends V>[] entries)
| 187 | * @throws AssertionError if the given {@code Map} does not contain the given entries. |
| 188 | */ |
| 189 | public <K, V> void assertContains(AssertionInfo info, Map<K, V> actual, MapEntry<? extends K, ? extends V>[] entries) { |
| 190 | failIfNull(entries); |
| 191 | assertNotNull(info, actual); |
| 192 | // if both actual and values are empty, then assertion passes. |
| 193 | if (actual.isEmpty() && entries.length == 0) |
| 194 | return; |
| 195 | failIfEmptySinceActualIsNotEmpty(entries); |
| 196 | Set<MapEntry<? extends K, ? extends V>> notFound = new LinkedHashSet<MapEntry<? extends K, ? extends V>>(); |
| 197 | for (MapEntry<? extends K, ? extends V> entry : entries) { |
| 198 | if (!containsEntry(actual, entry)) { |
| 199 | notFound.add(entry); |
| 200 | } |
| 201 | } |
| 202 | if (notFound.isEmpty()) { |
| 203 | return; |
| 204 | } |
| 205 | throw failures.failure(info, shouldContain(actual, entries, notFound)); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Asserts that the given {@code Map} does not contain the given entries. |