@@ -440,10 +440,6 @@ private static <K, V> Map<K, V> clone(Map<K, V> map) throws NoSuchMethodExceptio
440440 }
441441 }
442442
443- private static boolean isSingletonMap (Map <?, ?> map ) {
444- return map .size () == 1 ;
445- }
446-
447443 private static boolean isMultiValueMapAdapterInstance (Map <?, ?> map ) {
448444 return isInstanceOf (map , "org.springframework.util.MultiValueMapAdapter" );
449445 }
@@ -457,16 +453,6 @@ private static boolean isInstanceOf(Object object, String className) {
457453 }
458454 }
459455
460- private static <K , V > Map <K , V > createEmptyMap (Map <K , V > map ) {
461- try {
462- Map <K , V > cloned = clone (map );
463- cloned .clear ();
464- return cloned ;
465- } catch (NoSuchMethodException | RuntimeException e ) {
466- return new LinkedHashMap <>();
467- }
468- }
469-
470456 public <K , V > void assertContainsValue (AssertionInfo info , Map <K , V > actual , V value ) {
471457 assertNotNull (info , actual );
472458 if (!containsValue (actual , value )) throw failures .failure (info , shouldContainValue (actual , value ));
@@ -565,16 +551,6 @@ public <K, V> void assertContainsExactly(AssertionInfo info, Map<K, V> actual, E
565551 failIfEntriesIsEmptySinceActualIsNotEmpty (info , actual , entries );
566552 assertHasSameSizeAs (info , actual , entries );
567553
568- if (isSingletonMap (actual )) {
569- // shortcut for any singleton map but specifically for org.apache.commons.collections4.map.SingletonMap that is immutable
570- // and fail when we try to remove elements from them in compareActualMapAndExpectedEntries
571- // we only have to compare the map unique element
572- if (!actual .containsKey (entries [0 ].getKey ()) || !actual .containsValue (entries [0 ].getValue ())) {
573- throw failures .failure (info , elementsDifferAtIndex (actual .entrySet ().iterator ().next (), entries [0 ], 0 ));
574- }
575- return ;
576- }
577-
578554 Set <Entry <? extends K , ? extends V >> notFound = new LinkedHashSet <>();
579555 Set <Entry <? extends K , ? extends V >> notExpected = new LinkedHashSet <>();
580556
@@ -583,15 +559,11 @@ public <K, V> void assertContainsExactly(AssertionInfo info, Map<K, V> actual, E
583559 if (notExpected .isEmpty () && notFound .isEmpty ()) {
584560 // check entries order
585561 int index = 0 ;
586- // Create a map with the same type as actual to use the Map built-in comparison, ex: maps string case insensitive keys.
587- Map <K , V > emptyMap = createEmptyMap (actual );
588562 for (K keyFromActual : actual .keySet ()) {
589- emptyMap .put (keyFromActual , null );
590- if (!emptyMap .containsKey (entries [index ].getKey ())) {
563+ if (!deepEquals (keyFromActual , entries [index ].getKey ())) {
591564 Entry <K , V > actualEntry = entry (keyFromActual , actual .get (keyFromActual ));
592565 throw failures .failure (info , elementsDifferAtIndex (actualEntry , entries [index ], index ));
593566 }
594- emptyMap .remove (keyFromActual );
595567 index ++;
596568 }
597569 // all entries are in the same order.
@@ -605,12 +577,7 @@ private <K, V> void compareActualMapAndExpectedEntries(Map<K, V> actual, Entry<?
605577 Set <Entry <? extends K , ? extends V >> notExpected ,
606578 Set <Entry <? extends K , ? extends V >> notFound ) {
607579 Map <K , V > expectedEntries = entriesToMap (entries );
608- Map <K , V > actualEntries = null ;
609- try {
610- actualEntries = clone (actual );
611- } catch (NoSuchMethodException | RuntimeException e ) {
612- actualEntries = new LinkedHashMap <>(actual );
613- }
580+ Map <K , V > actualEntries = new LinkedHashMap <>(actual );
614581 for (Entry <K , V > entry : expectedEntries .entrySet ()) {
615582 if (containsEntry (actualEntries , entry (entry .getKey (), entry .getValue ()))) {
616583 // this is an expected entry
0 commit comments