Best Assertj code snippet using org.assertj.core.internal.Maps.failIfEntriesIsEmptySinceActualIsNotEmpty
Source:Maps.java
...192 failIfNull(entries);193 assertNotNull(info, actual);194 // if both actual and values are empty, then assertion passes.195 if (actual.isEmpty() && entries.length == 0) return;196 failIfEntriesIsEmptySinceActualIsNotEmpty(info, actual, entries);197 failIfAnyEntryNotFoundInActualMap(info, actual, entries);198 }199 @SuppressWarnings("unchecked")200 public <K, V> void assertContainsAllEntriesOf(AssertionInfo info, Map<K, V> actual, Map<? extends K, ? extends V> other) {201 failIfNull(other);202 assertNotNull(info, actual);203 // assertion passes if other is empty since actual contains all other entries.204 if (other.isEmpty()) return;205 failIfAnyEntryNotFoundInActualMap(info, actual, other.entrySet().toArray(new Entry[0]));206 }207 public <K, V> void assertContainsAnyOf(AssertionInfo info, Map<K, V> actual, Entry<? extends K, ? extends V>[] entries) {208 failIfNull(entries);209 assertNotNull(info, actual);210 // if both actual and values are empty, then assertion passes.211 if (actual.isEmpty() && entries.length == 0) return;212 failIfEntriesIsEmptySinceActualIsNotEmpty(info, actual, entries);213 for (Entry<? extends K, ? extends V> entry : entries) {214 if (containsEntry(actual, entry)) return;215 }216 throw failures.failure(info, shouldContainAnyOf(actual, entries));217 }218 public <K, V> void assertHasEntrySatisfying(AssertionInfo info, Map<K, V> actual, K key, Condition<? super V> valueCondition) {219 assertContainsKey(info, actual, key);220 conditions.assertIsNotNull(valueCondition);221 V value = actual.get(key);222 if (!valueCondition.matches(value)) throw failures.failure(info, elementsShouldBe(actual, value, valueCondition));223 }224 public <K, V> void assertHasEntrySatisfying(AssertionInfo info, Map<K, V> actual, K key,225 Consumer<? super V> valueRequirements) {226 assertContainsKey(info, actual, key);227 requireNonNull(valueRequirements, "The Consumer<V> expressing the assertions requirements must not be null");228 V value = actual.get(key);229 valueRequirements.accept(value);230 }231 public <K, V> void assertHasEntrySatisfying(AssertionInfo info, Map<K, V> actual,232 Condition<? super Entry<K, V>> entryCondition) {233 assertNotNull(info, actual);234 conditions.assertIsNotNull(entryCondition);235 for (Entry<K, V> entry : actual.entrySet()) {236 if (entryCondition.matches(entry)) return;237 }238 throw failures.failure(info, shouldContainEntry(actual, entryCondition));239 }240 public <K, V> void assertHasEntrySatisfyingConditions(AssertionInfo info, Map<K, V> actual, Condition<? super K> keyCondition,241 Condition<? super V> valueCondition) {242 assertNotNull(info, actual);243 conditions.assertIsNotNull(keyCondition, "The condition to evaluate for entries key should not be null");244 conditions.assertIsNotNull(valueCondition, "The condition to evaluate for entries value should not be null");245 for (Entry<K, V> entry : actual.entrySet()) {246 if (keyCondition.matches(entry.getKey()) && valueCondition.matches(entry.getValue())) return;247 }248 throw failures.failure(info, shouldContainEntry(actual, keyCondition, valueCondition));249 }250 public <K> void assertHasKeySatisfying(AssertionInfo info, Map<K, ?> actual, Condition<? super K> keyCondition) {251 assertNotNull(info, actual);252 conditions.assertIsNotNull(keyCondition);253 for (K key : actual.keySet()) {254 if (keyCondition.matches(key)) return;255 }256 throw failures.failure(info, shouldContainKey(actual, keyCondition));257 }258 public <V> void assertHasValueSatisfying(AssertionInfo info, Map<?, V> actual, Condition<? super V> valueCondition) {259 assertNotNull(info, actual);260 conditions.assertIsNotNull(valueCondition);261 for (V value : actual.values()) {262 if (valueCondition.matches(value)) return;263 }264 throw failures.failure(info, shouldContainValue(actual, valueCondition));265 }266 public <K, V> void assertDoesNotContain(AssertionInfo info, Map<K, V> actual, Entry<? extends K, ? extends V>[] entries) {267 failIfNullOrEmpty(entries);268 assertNotNull(info, actual);269 Set<Entry<? extends K, ? extends V>> found = new LinkedHashSet<>();270 for (Entry<? extends K, ? extends V> entry : entries) {271 if (containsEntry(actual, entry)) {272 found.add(entry);273 }274 }275 if (!found.isEmpty()) throw failures.failure(info, shouldNotContain(actual, entries, found));276 }277 public <K, V> void assertContainsKeys(AssertionInfo info, Map<K, V> actual, K[] keys) {278 assertNotNull(info, actual);279 requireNonNull(keys, keysToLookForIsNull("array of keys"));280 if (actual.isEmpty() && keys.length == 0) return;281 failIfEmpty(keys, keysToLookForIsEmpty("array of keys"));282 Set<K> notFound = getNotFoundKeys(actual, keys);283 if (!notFound.isEmpty()) throw failures.failure(info, shouldContainKeys(actual, notFound));284 }285 public <K, V> void assertContainsKey(AssertionInfo info, Map<K, V> actual, K key) {286 assertContainsKeys(info, actual, array(key));287 }288 public <K, V> void assertDoesNotContainKey(AssertionInfo info, Map<K, V> actual, K key) {289 assertNotNull(info, actual);290 if (containsKey(actual, key)) throw failures.failure(info, shouldNotContainKey(actual, key));291 }292 public <K, V> void assertDoesNotContainKeys(AssertionInfo info, Map<K, V> actual, K[] keys) {293 assertNotNull(info, actual);294 requireNonNull(keys, keysToLookForIsNull("array of keys"));295 Set<K> found = getFoundKeys(actual, keys);296 if (!found.isEmpty()) throw failures.failure(info, shouldNotContainKeys(actual, found));297 }298 public <K, V> void assertContainsOnlyKeys(AssertionInfo info, Map<K, V> actual, K[] keys) {299 assertContainsOnlyKeys(info, actual, "array of keys", keys);300 }301 public <K, V> void assertContainsOnlyKeys(AssertionInfo info, Map<K, V> actual, Iterable<? extends K> keys) {302 assertContainsOnlyKeys(info, actual, "keys iterable", toArray(keys));303 }304 private <K, V> void assertContainsOnlyKeys(AssertionInfo info, Map<K, V> actual, String placeholderForErrorMessages, K[] keys) {305 assertNotNull(info, actual);306 requireNonNull(keys, keysToLookForIsNull(placeholderForErrorMessages));307 if (actual.isEmpty() && keys.length == 0) {308 return;309 }310 failIfEmpty(keys, keysToLookForIsEmpty(placeholderForErrorMessages));311 Set<K> notFound = getNotFoundKeys(actual, keys);312 Set<K> notExpected = getNotExpectedKeys(actual, keys);313 if (!notFound.isEmpty() || !notExpected.isEmpty())314 throw failures.failure(info, shouldContainOnlyKeys(actual, keys, notFound, notExpected));315 }316 private static <K> Set<K> getFoundKeys(Map<K, ?> actual, K[] expectedKeys) {317 // Stream API avoided for performance reasons318 Set<K> found = new LinkedHashSet<>();319 for (K expectedKey : expectedKeys) {320 if (containsKey(actual, expectedKey)) found.add(expectedKey);321 }322 return found;323 }324 private static <K> Set<K> getNotFoundKeys(Map<K, ?> actual, K[] expectedKeys) {325 // Stream API avoided for performance reasons326 Set<K> notFound = new LinkedHashSet<>();327 for (K expectedKey : expectedKeys) {328 if (!containsKey(actual, expectedKey)) notFound.add(expectedKey);329 }330 return notFound;331 }332 private static <K> boolean containsKey(Map<K, ?> actual, K key) {333 try {334 return actual.containsKey(key);335 } catch (NullPointerException e) {336 if (key == null) return false; // null keys not permitted337 throw e;338 }339 }340 private static <K> Set<K> getNotExpectedKeys(Map<K, ?> actual, K[] expectedKeys) {341 // Stream API avoided for performance reasons342 try {343 Map<K, ?> clonedMap = clone(actual);344 for (K expectedKey : expectedKeys) {345 clonedMap.remove(expectedKey);346 }347 return clonedMap.keySet();348 } catch (NoSuchMethodException | RuntimeException e) {349 // actual cannot be cloned or is unmodifiable, falling back to LinkedHashMap350 Map<K, ?> copiedMap = new LinkedHashMap<>(actual);351 for (K expectedKey : expectedKeys) {352 copiedMap.remove(expectedKey);353 }354 return copiedMap.keySet();355 }356 }357 @SuppressWarnings("unchecked")358 private static <K, V> Map<K, V> clone(Map<K, V> map) throws NoSuchMethodException {359 if (isMultiValueMapAdapterInstance(map)) throw new IllegalArgumentException("Cannot clone MultiValueMapAdapter");360 try {361 if (map instanceof Cloneable) {362 return (Map<K, V>) map.getClass().getMethod("clone").invoke(map);363 }364 try {365 // try with copying constructor366 return map.getClass().getConstructor(Map.class).newInstance(map);367 } catch (NoSuchMethodException e) {368 // try with default constructor369 Map<K, V> newMap = map.getClass().getConstructor().newInstance();370 newMap.putAll(map);371 return newMap;372 }373 } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) {374 throw new IllegalStateException(e);375 }376 }377 private static boolean isMultiValueMapAdapterInstance(Map<?, ?> map) {378 return isInstanceOf(map, "org.springframework.util.MultiValueMapAdapter");379 }380 private static boolean isInstanceOf(Object object, String className) {381 try {382 Class<?> type = Class.forName(className);383 return type.isInstance(object);384 } catch (ClassNotFoundException e) {385 return false;386 }387 }388 public <K, V> void assertContainsValue(AssertionInfo info, Map<K, V> actual, V value) {389 assertNotNull(info, actual);390 if (!containsValue(actual, value)) throw failures.failure(info, shouldContainValue(actual, value));391 }392 public <K, V> void assertContainsValues(AssertionInfo info, Map<K, V> actual, V[] values) {393 assertNotNull(info, actual);394 requireNonNull(values, "The array of values to look for should not be null");395 if (actual.isEmpty() && values.length == 0) return;396 failIfEmpty(values, valuesToLookForIsEmpty());397 Set<V> notFound = getNotFoundValues(actual, values);398 if (!notFound.isEmpty()) throw failures.failure(info, shouldContainValues(actual, notFound));399 }400 public <K, V> void assertDoesNotContainValue(AssertionInfo info, Map<K, V> actual, V value) {401 assertNotNull(info, actual);402 if (containsValue(actual, value)) throw failures.failure(info, shouldNotContainValue(actual, value));403 }404 private static <V> Set<V> getNotFoundValues(Map<?, V> actual, V[] expectedValues) {405 // Stream API avoided for performance reasons406 Set<V> notFound = new LinkedHashSet<>();407 for (V expectedValue : expectedValues) {408 if (!containsValue(actual, expectedValue)) notFound.add(expectedValue);409 }410 return notFound;411 }412 private static <V> boolean containsValue(Map<?, V> actual, V value) {413 try {414 return actual.containsValue(value);415 } catch (NullPointerException e) {416 if (value == null) return false; // null values not permitted417 throw e;418 }419 }420 public <K, V> void assertContainsOnly(AssertionInfo info, Map<K, V> actual, Entry<? extends K, ? extends V>[] entries) {421 doCommonContainsCheck(info, actual, entries);422 if (actual.isEmpty() && entries.length == 0) return;423 failIfEntriesIsEmptySinceActualIsNotEmpty(info, actual, entries);424 Set<Entry<? extends K, ? extends V>> notFound = getNotFoundEntries(actual, entries);425 Set<Entry<K, V>> notExpected = getNotExpectedEntries(actual, entries);426 if (!(notFound.isEmpty() && notExpected.isEmpty()))427 throw failures.failure(info, shouldContainOnly(actual, entries, notFound, notExpected));428 }429 private static <K, V> Set<Entry<? extends K, ? extends V>> getNotFoundEntries(Map<K, V> actual,430 Entry<? extends K, ? extends V>[] entries) {431 // Stream API avoided for performance reasons432 Set<Entry<? extends K, ? extends V>> notFound = new LinkedHashSet<>();433 for (Entry<? extends K, ? extends V> entry : entries) {434 if (!containsEntry(actual, entry)) notFound.add(entry);435 }436 return notFound;437 }438 private static <K, V> Set<Entry<K, V>> getNotExpectedEntries(Map<K, V> actual, Entry<? extends K, ? extends V>[] entries) {439 // Stream API avoided for performance reasons440 Set<Entry<K, V>> notExpected = new LinkedHashSet<>();441 for (Entry<K, V> entry : mapWithoutExpectedEntries(actual, entries).entrySet()) {442 MapEntry<K, V> mapEntry = entry(entry.getKey(), entry.getValue());443 notExpected.add(mapEntry);444 }445 return notExpected;446 }447 private static <K, V> Map<K, V> mapWithoutExpectedEntries(Map<K, V> actual, Entry<? extends K, ? extends V>[] expectedEntries) {448 // Stream API avoided for performance reasons449 try {450 Map<K, V> clonedMap = clone(actual);451 removeEntries(clonedMap, expectedEntries);452 return clonedMap;453 } catch (NoSuchMethodException | RuntimeException e) {454 // actual cannot be cloned or is unmodifiable, falling back to LinkedHashMap455 Map<K, V> copiedMap = new LinkedHashMap<>(actual);456 removeEntries(copiedMap, expectedEntries);457 return copiedMap;458 }459 }460 private static <K, V> void removeEntries(Map<K, V> map, Entry<? extends K, ? extends V>[] entries) {461 for (Entry<? extends K, ? extends V> entry : entries) {462 // must perform deep equals comparison on values as Map.remove(Object, Object) relies on463 // Objects.equals which does not handle deep equality (e.g. arrays in map entry values)464 if (containsEntry(map, entry)) map.remove(entry.getKey());465 }466 }467 public <K, V> void assertContainsExactly(AssertionInfo info, Map<K, V> actual, Entry<? extends K, ? extends V>[] entries) {468 doCommonContainsCheck(info, actual, entries);469 if (actual.isEmpty() && entries.length == 0) return;470 failIfEntriesIsEmptySinceActualIsNotEmpty(info, actual, entries);471 assertHasSameSizeAs(info, actual, entries);472 Set<Entry<? extends K, ? extends V>> notFound = new LinkedHashSet<>();473 Set<Entry<? extends K, ? extends V>> notExpected = new LinkedHashSet<>();474 compareActualMapAndExpectedEntries(actual, entries, notExpected, notFound);475 if (notExpected.isEmpty() && notFound.isEmpty()) {476 // check entries order477 int index = 0;478 for (K keyFromActual : actual.keySet()) {479 if (!deepEquals(keyFromActual, entries[index].getKey())) {480 Entry<K, V> actualEntry = entry(keyFromActual, actual.get(keyFromActual));481 throw failures.failure(info, elementsDifferAtIndex(actualEntry, entries[index], index));482 }483 index++;484 }485 // all entries are in the same order.486 return;487 }488 throw failures.failure(info, shouldContainExactly(actual, asList(entries), notFound, notExpected));489 }490 private <K, V> void compareActualMapAndExpectedEntries(Map<K, V> actual, Entry<? extends K, ? extends V>[] entries,491 Set<Entry<? extends K, ? extends V>> notExpected,492 Set<Entry<? extends K, ? extends V>> notFound) {493 Map<K, V> expectedEntries = entriesToMap(entries);494 Map<K, V> actualEntries = new LinkedHashMap<>(actual);495 for (Entry<K, V> entry : expectedEntries.entrySet()) {496 if (containsEntry(actualEntries, entry(entry.getKey(), entry.getValue()))) {497 // this is an expected entry498 actualEntries.remove(entry.getKey());499 } else {500 // this is a not found entry501 notFound.add(entry(entry.getKey(), entry.getValue()));502 }503 }504 // All remaining entries from actual copy are not expected entries.505 for (Entry<K, V> entry : actualEntries.entrySet()) {506 notExpected.add(entry(entry.getKey(), entry.getValue()));507 }508 }509 private <K, V> void doCommonContainsCheck(AssertionInfo info, Map<K, V> actual, Entry<? extends K, ? extends V>[] entries) {510 assertNotNull(info, actual);511 failIfNull(entries);512 }513 private <K, V> void failIfAnyEntryNotFoundInActualMap(AssertionInfo info, Map<K, V> actual,514 Entry<? extends K, ? extends V>[] entries) {515 Set<Entry<? extends K, ? extends V>> entriesWithKeyNotFound = new LinkedHashSet<>();516 Set<Entry<? extends K, ? extends V>> entriesWithWrongValue = new LinkedHashSet<>();517 for (Entry<? extends K, ? extends V> entry : entries) {518 requireNonNull(entry, ErrorMessages.entryToLookForIsNull());519 if (!actual.containsKey(entry.getKey())) entriesWithKeyNotFound.add(entry);520 else if (!containsEntry(actual, entry)) entriesWithWrongValue.add(entry); // can only be wrong value since key was found521 }522 if (!entriesWithWrongValue.isEmpty() || !entriesWithKeyNotFound.isEmpty())523 throw failures.failure(info, shouldContainEntries(actual, entries, entriesWithWrongValue, entriesWithKeyNotFound,524 info.representation()));525 }526 private static <K, V> Map<K, V> entriesToMap(Entry<? extends K, ? extends V>[] entries) {527 Map<K, V> expectedEntries = new LinkedHashMap<>();528 for (Entry<? extends K, ? extends V> entry : entries) {529 expectedEntries.put(entry.getKey(), entry.getValue());530 }531 return expectedEntries;532 }533 private static <K> void failIfEmpty(K[] keys, String errorMessage) {534 checkArgument(keys.length > 0, errorMessage);535 }536 private static <K, V> void failIfEmpty(Entry<? extends K, ? extends V>[] entries) {537 checkArgument(entries.length > 0, "The array of entries to look for should not be empty");538 }539 private static <K, V> void failIfNullOrEmpty(Entry<? extends K, ? extends V>[] entries) {540 failIfNull(entries);541 failIfEmpty(entries);542 }543 private static <K, V> void failIfNull(Entry<? extends K, ? extends V>[] entries) {544 requireNonNull(entries, ErrorMessages.entriesToLookForIsNull());545 }546 private static <K, V> void failIfNull(Map<? extends K, ? extends V> map) {547 requireNonNull(map, ErrorMessages.mapOfEntriesToLookForIsNull());548 }549 private static <K, V> boolean containsEntry(Map<K, V> actual, Entry<? extends K, ? extends V> entry) {550 requireNonNull(entry, ErrorMessages.entryToLookForIsNull());551 return actual.containsKey(entry.getKey()) && deepEquals(actual.get(entry.getKey()), entry.getValue());552 }553 private void assertNotNull(AssertionInfo info, Map<?, ?> actual) {554 Objects.instance().assertNotNull(info, actual);555 }556 // this should be only called when actual is not empty557 private <K, V> void failIfEntriesIsEmptySinceActualIsNotEmpty(AssertionInfo info, Map<K, V> actual,558 Entry<? extends K, ? extends V>[] entries) {559 if (entries.length == 0) throw failures.failure(info, shouldBeEmpty(actual));560 }561}...
failIfEntriesIsEmptySinceActualIsNotEmpty
Using AI Code Generation
1package org.assertj.core.internal;2import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty;3import static org.assertj.core.util.IterableUtil.sizeOf;4import java.util.Map;5import org.assertj.core.api.AssertionInfo;6import org.assertj.core.internal.ErrorMessages;7import org.assertj.core.internal.Maps;8import org.assertj.core.util.VisibleForTesting;9public class Maps_assertIsEmpty_Test extends MapsBaseTest {10 protected Maps maps = Maps.instance();11 protected void initActualMap() {12 actual.put("name", "Yoda");13 }14 protected void verify_internal_effects() {15 }16 public void should_pass_if_actual_is_empty() {17 actual.clear();18 maps.assertIsEmpty(info, actual);19 }20 public void should_fail_if_actual_is_null() {21 thrown.expectAssertionError(actualIsNull());22 maps.assertIsEmpty(info, null);23 }24 public void should_fail_if_actual_is_not_empty() {25 thrown.expectAssertionError(shouldNotBeEmpty());26 maps.assertIsEmpty(info, actual);27 }28}29package org.assertj.core.internal;30import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty;31import static org.assertj.core.util.IterableUtil.sizeOf;32import java.util.Map;33import org.assertj.core.api.AssertionInfo;34import org.assertj.core.internal.ErrorMessages;35import org.assertj.core.internal.Maps;36import org.assertj.core.util.VisibleForTesting;37public class Maps_assertIsEmpty_Test extends MapsBaseTest {38 protected Maps maps = Maps.instance();39 protected void initActualMap() {40 actual.put("name", "Yoda");41 }42 protected void verify_internal_effects() {43 }44 public void should_pass_if_actual_is_empty() {45 actual.clear();46 maps.assertIsEmpty(info, actual);47 }48 public void should_fail_if_actual_is_null() {49 thrown.expectAssertionError(actualIsNull());50 maps.assertIsEmpty(info, null);51 }52 public void should_fail_if_actual_is_not_empty() {53 thrown.expectAssertionError(shouldNotBeEmpty());54 maps.assertIsEmpty(info, actual);55 }56}
failIfEntriesIsEmptySinceActualIsNotEmpty
Using AI Code Generation
1public void should_fail_if_actual_is_empty_and_expected_is_not() {2 AssertionInfo info = someInfo();3 Map<String, String> actual = new HashMap<>();4 Map<String, String> expected = new HashMap<>();5 expected.put("name", "Yoda");6 try {7 maps.assertContainsAllEntriesOf(info, actual, expected);8 } catch (AssertionError e) {9 verify(failures).failure(info, shouldContainAllEntriesOf(actual, expected));10 return;11 }12 failBecauseExpectedAssertionErrorWasNotThrown();13}14public void should_fail_if_actual_does_not_contain_all_entries_of_expected() {15 AssertionInfo info = someInfo();16 Map<String, String> actual = new HashMap<>();17 actual.put("name", "Yoda");18 actual.put("color", "green");19 Map<String, String> expected = new HashMap<>();20 expected.put("name", "Yoda");21 expected.put("color", "blue");22 try {23 maps.assertContainsAllEntriesOf(info, actual, expected);24 } catch (AssertionError e) {25 verify(failures).failure(info, shouldContainAllEntriesOf(actual, expected));26 return;27 }28 failBecauseExpectedAssertionErrorWasNotThrown();29}30public void should_pass_if_actual_contains_all_entries_of_expected() {31 Map<String, String> actual = new HashMap<>();32 actual.put("name", "Yoda");33 actual.put("color", "green");34 Map<String, String> expected = new HashMap<>();35 expected.put("name", "Yoda");36 maps.assertContainsAllEntriesOf(someInfo(), actual, expected);37}38public void should_pass_if_actual_contains_all_entries_of_expected_in_different_order() {39 Map<String, String> actual = new HashMap<>();40 actual.put("name", "Yoda");41 actual.put("color", "green");42 Map<String, String> expected = new HashMap<>();43 expected.put("color", "green");44 expected.put("name", "Yoda");45 maps.assertContainsAllEntriesOf(someInfo(), actual, expected);46}47public void should_pass_if_actual_contains_all_entries_of_expected_with_null_values() {48 Map<String, String> actual = new HashMap<>();49 actual.put("name", "Yoda");50 actual.put("color", null);51 Map<String, String> expected = new HashMap<>();52 expected.put("
failIfEntriesIsEmptySinceActualIsNotEmpty
Using AI Code Generation
1package org.assertj.core.internal;2import static org.assertj.core.error.ShouldBeEmpty.shouldBeEmpty;3import static org.assertj.core.error.ShouldContainOnly.shouldContainOnly;4import static org.assertj.core.error.ShouldContainOnlyKeys.shouldContainOnlyKeys;5import static org.assertj.core.error.ShouldContainValue.shouldContainValue;6import static org.assertj.core.error.ShouldContainValues.shouldContainValues;7import static org.assertj.core.error.ShouldHaveSameSizeAs.shouldHaveSameSizeAs;8import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty;9import static org.assertj.core.error.ShouldNotContainValue.shouldNotContainValue;10import static org.assertj.core.error.ShouldNotContainValues.shouldNotContainValues;11import static org.assertj.core.util.Arrays.isArray;12import static org.assertj.core.util.IterableUtil.toArray;13import static org.assertj.core.util.IterableUtil.sizeOf;14import static org.assertj.core.util.Preconditions.checkNotNull;15import static org.assertj.core.util.Preconditions.checkNotEmpty;16import java.util.Arrays;17import java.util.Map;18import java.util.Map.Entry;19import org.assertj.core.api.AssertionInfo;20import org.assertj.core.data.MapEntry;21import org.assertj.core.util.VisibleForTesting;22public class Maps {23 private static final Maps INSTANCE = new Maps();24 public static Maps instance() {25 return INSTANCE;26 }27 Failures failures = Failures.instance();28 Maps() {29 }30 public void assertEmpty(AssertionInfo info, Map<?, ?> actual) {31 assertNotNull(info, actual);32 if (!actual.isEmpty()) throw failures.failure(info, shouldBeEmpty(actual));33 }
failIfEntriesIsEmptySinceActualIsNotEmpty
Using AI Code Generation
1import org.assertj.core.api.AbstractMapAssert;2import org.assertj.core.api.MapAssert;3import org.assertj.core.internal.Maps;4import org.assertj.core.internal.Objects;5import org.assertj.core.internal.StandardComparisonStrategy;6import org.assertj.core.internal.TypeComparators;7import org.assertj.core.util.VisibleForTesting;8import java.util.Map;9public class MapAssert<K, V> extends AbstractMapAssert<MapAssert<K, V>, Map<K, V>, K, V> {10 Maps maps = Maps.instance();11 public MapAssert(Map<K, V> actual) {12 super(actual, MapAssert.class);13 }14 * <pre><code class='java'> Map<String, Integer> agesByName = new HashMap<>();15 * agesByName.put("John", 25);16 * agesByName.put("Jane", 22);17 * assertThat(agesByName).contains(entry("John", 25));18 * assertThat(agesByName).contains(entry("Sylvain", 30));</code></pre>19 public MapAssert<K, V> contains(Map.Entry<? extends K, ? extends V> entry) {20 maps.assertContains(info, actual, entry);21 return myself;22 }23 * <pre><code class='java'> Map<String, Integer> agesByName = new HashMap<>();24 * agesByName.put("John", 25
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!