Polishing

This commit is contained in:
Sam Brannen 2023-04-26 11:09:20 +02:00
parent 1c7ceaa2ca
commit ce3e9b0c29
6 changed files with 17 additions and 42 deletions

View File

@ -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;
}

View File

@ -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<String> getReservedDefaultProfiles() {
return Collections.emptySet();
return Set.of();
}
}
@ -64,7 +62,7 @@ class CustomEnvironmentTests {
class CustomEnvironment extends AbstractEnvironment {
@Override
protected Set<String> getReservedDefaultProfiles() {
return Collections.singleton("rd1");
return Set.of("rd1");
}
}
@ -79,10 +77,7 @@ class CustomEnvironmentTests {
@Override
@SuppressWarnings("serial")
protected Set<String> 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";
}
}

View File

@ -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<String, Object> map1 = new HashMap<>() {{
put("a", "b");
}};
Map<String, Object> map2 = new HashMap<>() {{
put("c", "d");
}};
Map<String, Object> map1 = Map.of("a", "b");
Map<String, Object> map2 = Map.of("c", "d");
Properties props1 = new Properties() {{
setProperty("a", "b");
}};
@ -69,12 +64,8 @@ class PropertySourceTests {
@Test
@SuppressWarnings("serial")
void collectionsOperations() {
Map<String, Object> map1 = new HashMap<>() {{
put("a", "b");
}};
Map<String, Object> map2 = new HashMap<>() {{
put("c", "d");
}};
Map<String, Object> map1 = Map.of("a", "b");
Map<String, Object> map2 = Map.of("c", "d");
PropertySource<?> ps1 = new MapPropertySource("ps1", map1);
ps1.getSource();

View File

@ -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.

View File

@ -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<String, Supplier<Object>>() {{
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");
}
}

View File

@ -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<String, Object> model = Collections.unmodifiableMap(new HashMap<String, Object>() {{
put("foo", "bar");
put("I", 1L);
}});
private static final Map<String, Object> model = Map.of("foo", "bar", "I", 1L);
private static final String url = "forward-to";