diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java index bd2535dab86..08f45994289 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java @@ -21,7 +21,7 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.util.HashSet; +import java.util.Set; import example.scannable.CustomComponent; import example.scannable.CustomStereotype; @@ -396,9 +396,7 @@ class ComponentScanWithCustomTypeFilter { @SuppressWarnings({ "rawtypes", "serial", "unchecked" }) public static CustomAutowireConfigurer customAutowireConfigurer() { CustomAutowireConfigurer cac = new CustomAutowireConfigurer(); - cac.setCustomQualifierTypes(new HashSet() {{ - add(ComponentScanParserTests.CustomAnnotation.class); - }}); + cac.setCustomQualifierTypes(Set.of(ComponentScanParserTests.CustomAnnotation.class)); return cac; } diff --git a/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java b/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java index 258fc362269..b3294c30161 100644 --- a/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java +++ b/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java @@ -16,8 +16,6 @@ package org.springframework.core.env; -import java.util.Collections; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -51,7 +49,7 @@ class CustomEnvironmentTests { class CustomEnvironment extends AbstractEnvironment { @Override protected Set getReservedDefaultProfiles() { - return Collections.emptySet(); + return Set.of(); } } @@ -64,7 +62,7 @@ class CustomEnvironmentTests { class CustomEnvironment extends AbstractEnvironment { @Override protected Set getReservedDefaultProfiles() { - return Collections.singleton("rd1"); + return Set.of("rd1"); } } @@ -79,10 +77,7 @@ class CustomEnvironmentTests { @Override @SuppressWarnings("serial") protected Set getReservedDefaultProfiles() { - return new HashSet<>() {{ - add("rd1"); - add("rd2"); - }}; + return Set.of("rd1", "rd2"); } } @@ -151,7 +146,7 @@ class CustomEnvironmentTests { @Override @Nullable public String getProperty(String key) { - return super.getProperty(key)+"-test"; + return super.getProperty(key) + "-test"; } } diff --git a/spring-core/src/test/java/org/springframework/core/env/PropertySourceTests.java b/spring-core/src/test/java/org/springframework/core/env/PropertySourceTests.java index beeaf18e8ea..e8131bc1276 100644 --- a/spring-core/src/test/java/org/springframework/core/env/PropertySourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/env/PropertySourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.core.env; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; @@ -37,12 +36,8 @@ class PropertySourceTests { @Test @SuppressWarnings("serial") void equals() { - Map map1 = new HashMap<>() {{ - put("a", "b"); - }}; - Map map2 = new HashMap<>() {{ - put("c", "d"); - }}; + Map map1 = Map.of("a", "b"); + Map map2 = Map.of("c", "d"); Properties props1 = new Properties() {{ setProperty("a", "b"); }}; @@ -69,12 +64,8 @@ class PropertySourceTests { @Test @SuppressWarnings("serial") void collectionsOperations() { - Map map1 = new HashMap<>() {{ - put("a", "b"); - }}; - Map map2 = new HashMap<>() {{ - put("c", "d"); - }}; + Map map1 = Map.of("a", "b"); + Map map2 = Map.of("c", "d"); PropertySource ps1 = new MapPropertySource("ps1", map1); ps1.getSource(); diff --git a/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java b/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java index 8ba58a63e54..c155247a92f 100644 --- a/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java +++ b/spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-test/src/test/java/org/springframework/test/context/support/DynamicValuesPropertySourceTests.java b/spring-test/src/test/java/org/springframework/test/context/support/DynamicValuesPropertySourceTests.java index 632eaf8f084..e831c1f19e3 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/DynamicValuesPropertySourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/DynamicValuesPropertySourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,7 @@ package org.springframework.test.context.support; -import java.util.HashMap; -import java.util.function.Supplier; +import java.util.Map; import org.junit.jupiter.api.Test; @@ -33,10 +32,7 @@ class DynamicValuesPropertySourceTests { @SuppressWarnings("serial") private final DynamicValuesPropertySource source = new DynamicValuesPropertySource("test", - new HashMap>() {{ - put("a", () -> "A"); - put("b", () -> "B"); - }}); + Map.of("a", () -> "A", "b", () -> "B")); @Test @@ -63,7 +59,7 @@ class DynamicValuesPropertySourceTests { @Test void getPropertyNamesReturnsNames() { - assertThat(this.source.getPropertyNames()).containsExactly("a", "b"); + assertThat(this.source.getPropertyNames()).containsExactlyInAnyOrder("a", "b"); } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java index 9467750ef8a..72f04a1eb9f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/InternalResourceViewTests.java @@ -16,8 +16,6 @@ package org.springframework.web.servlet.view; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; import jakarta.servlet.http.HttpServletRequest; @@ -46,10 +44,7 @@ import static org.mockito.Mockito.verify; public class InternalResourceViewTests { @SuppressWarnings("serial") - private static final Map model = Collections.unmodifiableMap(new HashMap() {{ - put("foo", "bar"); - put("I", 1L); - }}); + private static final Map model = Map.of("foo", "bar", "I", 1L); private static final String url = "forward-to";