diff --git a/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java b/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java index 4deac3c8a99..b6d38af1818 100644 --- a/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java +++ b/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java @@ -341,11 +341,7 @@ public class DefaultContextCache implements ContextCache { } // Remove empty entries from the hierarchy map. - for (Map.Entry> entry : this.hierarchyMap.entrySet()) { - if (entry.getValue().isEmpty()) { - this.hierarchyMap.remove(entry.getKey()); - } - } + this.hierarchyMap.entrySet().removeIf(entry -> entry.getValue().isEmpty()); } private void remove(List removedContexts, MergedContextConfiguration key) {