diff --git a/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java b/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java index 0afce648344..e5189de0835 100644 --- a/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java @@ -195,14 +195,22 @@ public class PagedListHolderTests { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MockFilter)) return false; + if (this == o) { + return true; + } + if (!(o instanceof MockFilter mockFilter)) { + return false; + } - final MockFilter mockFilter = (MockFilter) o; - - if (!age.equals(mockFilter.age)) return false; - if (!extendedInfo.equals(mockFilter.extendedInfo)) return false; - if (!name.equals(mockFilter.name)) return false; + if (!age.equals(mockFilter.age)) { + return false; + } + if (!extendedInfo.equals(mockFilter.extendedInfo)) { + return false; + } + if (!name.equals(mockFilter.name)) { + return false; + } return true; } diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/NestedTestBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/NestedTestBean.java index ea26ec0072c..1fb6b60081d 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/NestedTestBean.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/NestedTestBean.java @@ -44,10 +44,9 @@ public class NestedTestBean implements INestedTestBean { @Override public boolean equals(Object obj) { - if (!(obj instanceof NestedTestBean)) { + if (!(obj instanceof NestedTestBean ntb)) { return false; } - NestedTestBean ntb = (NestedTestBean) obj; return this.company.equals(ntb.company); } diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java index 6f9436906cc..c406c5c47b0 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java @@ -64,10 +64,9 @@ public class SerializablePerson implements Person, Serializable { @Override public boolean equals(Object other) { - if (!(other instanceof SerializablePerson)) { + if (!(other instanceof SerializablePerson p)) { return false; } - SerializablePerson p = (SerializablePerson) other; return p.age == age && ObjectUtils.nullSafeEquals(name, p.name); } diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java index ed54d0d05f4..ec9b7428633 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java @@ -468,10 +468,9 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt if (this == other) { return true; } - if (!(other instanceof TestBean)) { + if (!(other instanceof TestBean tb2)) { return false; } - TestBean tb2 = (TestBean) other; return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age); } diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/factory/xml/AbstractBeanFactoryTests.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/factory/xml/AbstractBeanFactoryTests.java index 307a9d64c12..3062dc62dcd 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/factory/xml/AbstractBeanFactoryTests.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/factory/xml/AbstractBeanFactoryTests.java @@ -261,11 +261,9 @@ public abstract class AbstractBeanFactoryTests { @Test public void aliasing() { BeanFactory bf = getBeanFactory(); - if (!(bf instanceof ConfigurableBeanFactory)) { + if (!(bf instanceof ConfigurableBeanFactory cbf)) { return; } - ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) bf; - String alias = "rods alias"; assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java index cb405b95989..5b5c5de1bf6 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java @@ -1358,7 +1358,7 @@ class ConfigurationClassPostProcessorTests { @Bean public Repository stringRepo() { - return new Repository() { + return new Repository<>() { @Override public String toString() { return "Repository"; @@ -1368,7 +1368,7 @@ class ConfigurationClassPostProcessorTests { @Bean public Repository integerRepo() { - return new Repository() { + return new Repository<>() { @Override public String toString() { return "Repository"; @@ -1378,7 +1378,7 @@ class ConfigurationClassPostProcessorTests { @Bean public Repository genericRepo() { - return new Repository() { + return new Repository<>() { @Override public String toString() { return "Repository"; @@ -1423,7 +1423,7 @@ class ConfigurationClassPostProcessorTests { @Bean @Scope("prototype") public Repository stringRepo() { - return new Repository() { + return new Repository<>() { @Override public String toString() { return "Repository"; @@ -1434,7 +1434,7 @@ class ConfigurationClassPostProcessorTests { @Bean @Scope("prototype") public Repository integerRepo() { - return new Repository() { + return new Repository<>() { @Override public String toString() { return "Repository"; @@ -1446,7 +1446,7 @@ class ConfigurationClassPostProcessorTests { @Scope("prototype") @SuppressWarnings("rawtypes") public Repository genericRepo() { - return new Repository() { + return new Repository<>() { @Override public String toString() { return "Repository"; @@ -1468,7 +1468,7 @@ class ConfigurationClassPostProcessorTests { @Bean @Scope(scopeName = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS) public Repository stringRepo() { - return new Repository() { + return new Repository<>() { @Override public String toString() { return "Repository"; @@ -1479,7 +1479,7 @@ class ConfigurationClassPostProcessorTests { @Bean @PrototypeScoped public Repository integerRepo() { - return new Repository() { + return new Repository<>() { @Override public String toString() { return "Repository"; diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationWithFactoryBeanBeanEarlyDeductionTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationWithFactoryBeanBeanEarlyDeductionTests.java index 833e357f006..74688cd5d81 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationWithFactoryBeanBeanEarlyDeductionTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationWithFactoryBeanBeanEarlyDeductionTests.java @@ -95,7 +95,7 @@ public class ConfigurationWithFactoryBeanBeanEarlyDeductionTests { beanDefinition.setFactoryBeanName("factoryBean"); beanDefinition.setFactoryMethodName("myBean"); GenericApplicationContext context = new GenericApplicationContext(); - try { + try (context) { context.registerBeanDefinition("factoryBean", factoryBeanDefinition); context.registerBeanDefinition("myBean", beanDefinition); NameCollectingBeanFactoryPostProcessor postProcessor = new NameCollectingBeanFactoryPostProcessor(); @@ -103,9 +103,6 @@ public class ConfigurationWithFactoryBeanBeanEarlyDeductionTests { context.refresh(); assertContainsMyBeanName(postProcessor.getNames()); } - finally { - context.close(); - } } private void assertPostFreeze(Class configurationClass) { @@ -118,16 +115,13 @@ public class ConfigurationWithFactoryBeanBeanEarlyDeductionTests { BeanFactoryPostProcessor... postProcessors) { NameCollectingBeanFactoryPostProcessor postProcessor = new NameCollectingBeanFactoryPostProcessor(); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - try { + try (context) { Arrays.stream(postProcessors).forEach(context::addBeanFactoryPostProcessor); context.addBeanFactoryPostProcessor(postProcessor); context.register(configurationClass); context.refresh(); assertContainsMyBeanName(postProcessor.getNames()); } - finally { - context.close(); - } } private void assertContainsMyBeanName(AnnotationConfigApplicationContext context) { diff --git a/spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java b/spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java index 8b73c760ee1..6e2161626a1 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java @@ -327,7 +327,7 @@ class PropertySourceAnnotationTests { @Bean FactoryBean testBean() { final String name = env.getProperty("testbean.name"); - return new FactoryBean() { + return new FactoryBean<>() { @Override public TestBean getObject() { return new TestBean(name); @@ -417,7 +417,7 @@ class PropertySourceAnnotationTests { @Override public org.springframework.core.env.PropertySource createPropertySource(String name, EncodedResource resource) throws IOException { Properties props = PropertiesLoaderUtils.loadProperties(resource); - return new org.springframework.core.env.PropertySource("my" + name, props) { + return new org.springframework.core.env.PropertySource<>("my" + name, props) { @Override public Object getProperty(String name) { String value = props.getProperty(name); diff --git a/spring-context/src/test/java/org/springframework/context/annotation/Spr15275Tests.java b/spring-context/src/test/java/org/springframework/context/annotation/Spr15275Tests.java index ac8222f620a..86080098d8f 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/Spr15275Tests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/Spr15275Tests.java @@ -78,7 +78,7 @@ public class Spr15275Tests { @Bean public FactoryBean foo() { - return new FactoryBean() { + return new FactoryBean<>() { @Override public Foo getObject() { return new Foo("x"); @@ -103,7 +103,7 @@ public class Spr15275Tests { @Bean public FactoryBean foo() { - return new AbstractFactoryBean() { + return new AbstractFactoryBean<>() { @Override public Foo createInstance() { return new Foo("x"); @@ -128,7 +128,7 @@ public class Spr15275Tests { @Bean public FactoryBean foo() { - return new AbstractFactoryBean() { + return new AbstractFactoryBean<>() { @Override public FooInterface createInstance() { return new Foo("x"); @@ -153,7 +153,7 @@ public class Spr15275Tests { @Bean public AbstractFactoryBean foo() { - return new AbstractFactoryBean() { + return new AbstractFactoryBean<>() { @Override public FooInterface createInstance() { return new Foo("x"); diff --git a/spring-context/src/test/java/org/springframework/context/annotation/Spr16179Tests.java b/spring-context/src/test/java/org/springframework/context/annotation/Spr16179Tests.java index 3bb81754644..8af39562cdc 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/Spr16179Tests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/Spr16179Tests.java @@ -53,7 +53,7 @@ public class Spr16179Tests { @Bean Assembler someAssembler() { - return new Assembler() {}; + return new Assembler<>() {}; } } diff --git a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java index 8c51dd29420..9c81b50e225 100644 --- a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java +++ b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java @@ -774,8 +774,7 @@ class AnnotationDrivenEventListenerTests { if (event.content == null) { return null; } - else if (event.content instanceof String) { - String s = (String) event.content; + else if (event.content instanceof String s) { if (s.equals("String")) { return event.content; } diff --git a/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java index d46d9fb61fa..9c5f1521870 100644 --- a/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java @@ -64,7 +64,7 @@ public class ConversionServiceFactoryBeanTests { converters.add(new ConverterFactory() { @Override public Converter getConverter(Class targetType) { - return new Converter () { + return new Converter<> () { @SuppressWarnings("unchecked") @Override public T convert(String source) { diff --git a/spring-context/src/test/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurerTests.java b/spring-context/src/test/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurerTests.java index 839b4c5395b..839044820ba 100644 --- a/spring-context/src/test/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurerTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurerTests.java @@ -265,7 +265,7 @@ public class PropertySourcesPlaceholderConfigurerTests { PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer(); - PropertySource ps = new PropertySource("simplePropertySource", new Object()) { + PropertySource ps = new PropertySource<>("simplePropertySource", new Object()) { @Override public Object getProperty(String key) { return "bar"; diff --git a/spring-context/src/test/java/org/springframework/jmx/export/NotificationListenerTests.java b/spring-context/src/test/java/org/springframework/jmx/export/NotificationListenerTests.java index c842a656fd3..4ccfbadfc84 100644 --- a/spring-context/src/test/java/org/springframework/jmx/export/NotificationListenerTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/export/NotificationListenerTests.java @@ -168,8 +168,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests { NotificationListenerBean listenerBean = new NotificationListenerBean(); listenerBean.setNotificationListener(listener); listenerBean.setNotificationFilter(notification -> { - if (notification instanceof AttributeChangeNotification) { - AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification; + if (notification instanceof AttributeChangeNotification changeNotification) { return "Name".equals(changeNotification.getAttributeName()); } else { @@ -450,8 +449,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests { @Override public void handleNotification(Notification notification, Object handback) { - if (notification instanceof AttributeChangeNotification) { - AttributeChangeNotification attNotification = (AttributeChangeNotification) notification; + if (notification instanceof AttributeChangeNotification attNotification) { String attributeName = attNotification.getAttributeName(); Integer currentCount = (Integer) this.attributeCounts.get(attributeName); diff --git a/spring-context/src/test/java/org/springframework/scheduling/support/BitsCronFieldTests.java b/spring-context/src/test/java/org/springframework/scheduling/support/BitsCronFieldTests.java index 37d6b30d4fd..961312a64ff 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/support/BitsCronFieldTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/support/BitsCronFieldTests.java @@ -108,7 +108,7 @@ class BitsCronFieldTests { } private static Condition set(int... indices) { - return new Condition(String.format("set bits %s", Arrays.toString(indices))) { + return new Condition<>(String.format("set bits %s", Arrays.toString(indices))) { @Override public boolean matches(BitsCronField value) { for (int index : indices) { @@ -122,7 +122,7 @@ class BitsCronFieldTests { } private static Condition setRange(int min, int max) { - return new Condition(String.format("set range %d-%d", min, max)) { + return new Condition<>(String.format("set range %d-%d", min, max)) { @Override public boolean matches(BitsCronField value) { for (int i = min; i < max; i++) { @@ -136,7 +136,7 @@ class BitsCronFieldTests { } private static Condition clear(int... indices) { - return new Condition(String.format("clear bits %s", Arrays.toString(indices))) { + return new Condition<>(String.format("clear bits %s", Arrays.toString(indices))) { @Override public boolean matches(BitsCronField value) { for (int index : indices) { @@ -150,7 +150,7 @@ class BitsCronFieldTests { } private static Condition clearRange(int min, int max) { - return new Condition(String.format("clear range %d-%d", min, max)) { + return new Condition<>(String.format("clear range %d-%d", min, max)) { @Override public boolean matches(BitsCronField value) { for (int i = min; i < max; i++) { diff --git a/spring-context/src/test/java/org/springframework/scheduling/support/CronExpressionTests.java b/spring-context/src/test/java/org/springframework/scheduling/support/CronExpressionTests.java index 5abce9e2de3..bed392c9f26 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/support/CronExpressionTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/support/CronExpressionTests.java @@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ class CronExpressionTests { - private static final Condition weekday = new Condition("weekday") { + private static final Condition weekday = new Condition<>("weekday") { @Override public boolean matches(Temporal value) { diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index 0c0e9c03647..ed9e495b7d5 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -85,8 +85,8 @@ public class GenericConversionService implements ConfigurableConversionService { @Override public void addConverter(Converter converter) { ResolvableType[] typeInfo = getRequiredTypeInfo(converter.getClass(), Converter.class); - if (typeInfo == null && converter instanceof DecoratingProxy) { - typeInfo = getRequiredTypeInfo(((DecoratingProxy) converter).getDecoratedClass(), Converter.class); + if (typeInfo == null && converter instanceof DecoratingProxy decoratingProxy) { + typeInfo = getRequiredTypeInfo(decoratingProxy.getDecoratedClass(), Converter.class); } if (typeInfo == null) { throw new IllegalArgumentException("Unable to determine source type and target type for your " + diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java index b156330eb76..7044ea7e419 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java @@ -85,8 +85,8 @@ final class SimpleAnnotationMetadataReadingVisitor extends ClassVisitor { if (supername != null && !isInterface(access)) { this.superClassName = toClassName(supername); } - for (int i = 0; i < interfaces.length; i++) { - this.interfaceNames.add(toClassName(interfaces[i])); + for (String element : interfaces) { + this.interfaceNames.add(toClassName(element)); } } diff --git a/spring-core/src/test/java/org/springframework/core/ParameterizedTypeReferenceTests.java b/spring-core/src/test/java/org/springframework/core/ParameterizedTypeReferenceTests.java index cb7e0414dfa..900def51de7 100644 --- a/spring-core/src/test/java/org/springframework/core/ParameterizedTypeReferenceTests.java +++ b/spring-core/src/test/java/org/springframework/core/ParameterizedTypeReferenceTests.java @@ -34,21 +34,21 @@ class ParameterizedTypeReferenceTests { @Test void stringTypeReference() { - ParameterizedTypeReference typeReference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference typeReference = new ParameterizedTypeReference<>() {}; assertThat(typeReference.getType()).isEqualTo(String.class); } @Test void mapTypeReference() throws Exception { Type mapType = getClass().getMethod("mapMethod").getGenericReturnType(); - ParameterizedTypeReference> typeReference = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> typeReference = new ParameterizedTypeReference<>() {}; assertThat(typeReference.getType()).isEqualTo(mapType); } @Test void listTypeReference() throws Exception { Type listType = getClass().getMethod("listMethod").getGenericReturnType(); - ParameterizedTypeReference> typeReference = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> typeReference = new ParameterizedTypeReference<>() {}; assertThat(typeReference.getType()).isEqualTo(listType); } diff --git a/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java b/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java index 058a72adf3b..f4ac87c81ce 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java @@ -1096,10 +1096,9 @@ class DefaultConversionServiceTests { @Override public boolean equals(Object o) { - if (!(o instanceof SSN)) { + if (!(o instanceof SSN ssn)) { return false; } - SSN ssn = (SSN) o; return this.value.equals(ssn.value); } @@ -1137,10 +1136,9 @@ class DefaultConversionServiceTests { @Override public boolean equals(Object o) { - if (!(o instanceof ISBN)) { + if (!(o instanceof ISBN isbn)) { return false; } - ISBN isbn = (ISBN) o; return this.value.equals(isbn.value); } 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 cc6098f52b8..2c87ad806d9 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 @@ -75,7 +75,7 @@ class CustomEnvironmentTests { @Override @SuppressWarnings("serial") protected Set getReservedDefaultProfiles() { - return new HashSet() {{ + return new HashSet<>() {{ add("rd1"); add("rd2"); }}; 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 11f90d5b8cf..6256832b2f6 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 @@ -37,10 +37,10 @@ class PropertySourceTests { @Test @SuppressWarnings("serial") void equals() { - Map map1 = new HashMap() {{ + Map map1 = new HashMap<>() {{ put("a", "b"); }}; - Map map2 = new HashMap() {{ + Map map2 = new HashMap<>() {{ put("c", "d"); }}; Properties props1 = new Properties() {{ @@ -69,10 +69,10 @@ class PropertySourceTests { @Test @SuppressWarnings("serial") void collectionsOperations() { - Map map1 = new HashMap() {{ + Map map1 = new HashMap<>() {{ put("a", "b"); }}; - Map map2 = new HashMap() {{ + Map map2 = new HashMap<>() {{ put("c", "d"); }}; diff --git a/spring-core/src/test/java/org/springframework/util/concurrent/FutureAdapterTests.java b/spring-core/src/test/java/org/springframework/util/concurrent/FutureAdapterTests.java index c192888517d..1ca2678043d 100644 --- a/spring-core/src/test/java/org/springframework/util/concurrent/FutureAdapterTests.java +++ b/spring-core/src/test/java/org/springframework/util/concurrent/FutureAdapterTests.java @@ -41,7 +41,7 @@ class FutureAdapterTests { @SuppressWarnings("unchecked") void setUp() { adaptee = mock(Future.class); - adapter = new FutureAdapter(adaptee) { + adapter = new FutureAdapter<>(adaptee) { @Override protected String adapt(Integer adapteeResult) throws ExecutionException { return adapteeResult.toString(); diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/security/TestPrincipal.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/security/TestPrincipal.java index 78c60b067b3..e3ec3085308 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/security/TestPrincipal.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/security/TestPrincipal.java @@ -41,10 +41,9 @@ public class TestPrincipal implements Principal { if (obj == this) { return true; } - if (!(obj instanceof TestPrincipal)) { + if (!(obj instanceof TestPrincipal p)) { return false; } - TestPrincipal p = (TestPrincipal) obj; return this.name.equals(p.name); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java index d0ba6edf8f9..1100dd748d2 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/support/LobSupportTests.java @@ -111,7 +111,7 @@ public class LobSupportTests { } private AbstractLobStreamingResultSetExtractor getResultSetExtractor(final boolean ex) { - AbstractLobStreamingResultSetExtractor lobRse = new AbstractLobStreamingResultSetExtractor() { + AbstractLobStreamingResultSetExtractor lobRse = new AbstractLobStreamingResultSetExtractor<>() { @Override protected void streamData(ResultSet rs) throws SQLException, IOException { diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java index e6c95ee1ddd..9b18659c0f0 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java @@ -107,7 +107,7 @@ public class SqlQueryTests { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt(1)).willReturn(1); - SqlQuery query = new MappingSqlQueryWithParameters() { + SqlQuery query = new MappingSqlQueryWithParameters<>() { @Override protected Integer mapRow(ResultSet rs, int rownum, @Nullable Object[] params, @Nullable Map context) throws SQLException { @@ -129,7 +129,7 @@ public class SqlQueryTests { @Test public void testQueryWithoutEnoughParams() { - MappingSqlQuery query = new MappingSqlQuery() { + MappingSqlQuery query = new MappingSqlQuery<>() { @Override protected Integer mapRow(ResultSet rs, int rownum) throws SQLException { return rs.getInt(1); @@ -147,7 +147,7 @@ public class SqlQueryTests { @Test public void testQueryWithMissingMapParams() { - MappingSqlQuery query = new MappingSqlQuery() { + MappingSqlQuery query = new MappingSqlQuery<>() { @Override protected Integer mapRow(ResultSet rs, int rownum) throws SQLException { return rs.getInt(1); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/KeyHolderTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/KeyHolderTests.java index c128b8fd3bc..d77f57c7f34 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/KeyHolderTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/KeyHolderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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,7 +16,6 @@ package org.springframework.jdbc.support; -import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Test; @@ -69,12 +68,7 @@ class KeyHolderTests { @Test void getKeyWithMultipleKeysInMap() { - @SuppressWarnings("serial") - Map m = new HashMap() {{ - put("key", 1); - put("seq", 2); - }}; - kh.getKeyList().add(m); + kh.getKeyList().add(Map.of("key", 1, "seq", 2)); assertThat(kh.getKeys()).as("two keys should be in the map").hasSize(2); assertThatExceptionOfType(InvalidDataAccessApiUsageException.class) @@ -110,10 +104,7 @@ class KeyHolderTests { @Test void getKeysWithMultipleKeyRows() { @SuppressWarnings("serial") - Map m = new HashMap() {{ - put("key", 1); - put("seq", 2); - }}; + Map m = Map.of("key", 1, "seq", 2); kh.getKeyList().addAll(asList(m, m)); assertThat(kh.getKeyList()).as("two rows should be in the list").hasSize(2); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java index 55fe630c881..d7315bb328a 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java @@ -61,10 +61,9 @@ public class TestSimpSubscription implements SimpSubscription { if (this == other) { return true; } - if (!(other instanceof SimpSubscription)) { + if (!(other instanceof SimpSubscription otherSubscription)) { return false; } - SimpSubscription otherSubscription = (SimpSubscription) other; return (ObjectUtils.nullSafeEquals(getSession(), otherSubscription.getSession()) && this.id.equals(otherSubscription.getId())); } diff --git a/spring-web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTests.java index f231495ddf9..427f21f6190 100644 --- a/spring-web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTests.java @@ -89,8 +89,7 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest final byte[] body = "Hello World".getBytes(StandardCharsets.UTF_8); request.getHeaders().setContentLength(body.length); - if (request instanceof StreamingHttpOutputMessage) { - StreamingHttpOutputMessage streamingRequest = (StreamingHttpOutputMessage) request; + if (request instanceof StreamingHttpOutputMessage streamingRequest) { streamingRequest.setBody(outputStream -> StreamUtils.copy(body, outputStream)); } else { @@ -111,8 +110,7 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/echo"), HttpMethod.POST); final byte[] body = "Hello World".getBytes(StandardCharsets.UTF_8); - if (request instanceof StreamingHttpOutputMessage) { - StreamingHttpOutputMessage streamingRequest = (StreamingHttpOutputMessage) request; + if (request instanceof StreamingHttpOutputMessage streamingRequest) { streamingRequest.setBody(outputStream -> { StreamUtils.copy(body, outputStream); outputStream.flush(); diff --git a/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlDecoderTests.java index 64acde26937..cd2d89b632d 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/xml/Jaxb2XmlDecoderTests.java @@ -289,8 +289,7 @@ public class Jaxb2XmlDecoderTests extends AbstractLeakCheckingTests { if (this == o) { return true; } - if (o instanceof TypePojo) { - TypePojo other = (TypePojo) o; + if (o instanceof TypePojo other) { return this.foo.equals(other.foo) && this.bar.equals(other.bar); } return false; diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java index 29cca1deef5..0bbabb216db 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java @@ -207,7 +207,7 @@ public class GsonHttpMessageConverterTests { @Test @SuppressWarnings("unchecked") public void readAndWriteParameterizedType() throws Exception { - ParameterizedTypeReference> beansList = new ParameterizedTypeReference>() { + ParameterizedTypeReference> beansList = new ParameterizedTypeReference<>() { }; String body = "[{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," + @@ -234,8 +234,8 @@ public class GsonHttpMessageConverterTests { @Test @SuppressWarnings("unchecked") public void writeParameterizedBaseType() throws Exception { - ParameterizedTypeReference> beansList = new ParameterizedTypeReference>() {}; - ParameterizedTypeReference> baseList = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> beansList = new ParameterizedTypeReference<>() {}; + ParameterizedTypeReference> baseList = new ParameterizedTypeReference<>() {}; String body = "[{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," + "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}]"; diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java index df3052bbaed..c0825f88d2f 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/JsonbHttpMessageConverterTests.java @@ -207,7 +207,7 @@ public class JsonbHttpMessageConverterTests { @Test @SuppressWarnings("unchecked") public void readAndWriteParameterizedType() throws Exception { - ParameterizedTypeReference> beansList = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> beansList = new ParameterizedTypeReference<>() {}; String body = "[{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," + "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}]"; @@ -233,8 +233,8 @@ public class JsonbHttpMessageConverterTests { @Test @SuppressWarnings("unchecked") public void writeParameterizedBaseType() throws Exception { - ParameterizedTypeReference> beansList = new ParameterizedTypeReference>() {}; - ParameterizedTypeReference> baseList = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> beansList = new ParameterizedTypeReference<>() {}; + ParameterizedTypeReference> baseList = new ParameterizedTypeReference<>() {}; String body = "[{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," + "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}]"; diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java index 76358796eab..2f5a3c6ae2e 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java @@ -281,7 +281,7 @@ public class MappingJackson2HttpMessageConverterTests { @Test @SuppressWarnings("unchecked") public void readAndWriteParameterizedType() throws Exception { - ParameterizedTypeReference> beansList = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> beansList = new ParameterizedTypeReference<>() {}; String body = "[{" + "\"bytes\":\"AQI=\"," + @@ -312,8 +312,8 @@ public class MappingJackson2HttpMessageConverterTests { @Test @SuppressWarnings("unchecked") public void writeParameterizedBaseType() throws Exception { - ParameterizedTypeReference> beansList = new ParameterizedTypeReference>() {}; - ParameterizedTypeReference> baseList = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> beansList = new ParameterizedTypeReference<>() {}; + ParameterizedTypeReference> baseList = new ParameterizedTypeReference<>() {}; String body = "[{" + "\"bytes\":\"AQI=\"," + @@ -468,7 +468,7 @@ public class MappingJackson2HttpMessageConverterTests { bar.setNumber(123); beans.add(bar); ParameterizedTypeReference> typeReference = - new ParameterizedTypeReference>() {}; + new ParameterizedTypeReference<>() {}; this.converter.writeInternal(beans, typeReference.getType(), outputMessage); diff --git a/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java index c12f97c05b6..b4b06af76db 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java @@ -224,8 +224,7 @@ public class Jaxb2CollectionHttpMessageConverterTests { if (this == o) { return true; } - if (o instanceof RootElement) { - RootElement other = (RootElement) o; + if (o instanceof RootElement other) { return this.type.equals(other.type); } return false; @@ -256,8 +255,7 @@ public class Jaxb2CollectionHttpMessageConverterTests { if (this == o) { return true; } - if (o instanceof TestType) { - TestType other = (TestType) o; + if (o instanceof TestType other) { return this.s.equals(other.s); } return false; diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java index 7a050dd67e7..cc1468359d0 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ChannelSendOperatorTests.java @@ -140,7 +140,7 @@ public class ChannelSendOperatorTests { return Mono.never(); }); - BaseSubscriber subscriber = new BaseSubscriber() {}; + BaseSubscriber subscriber = new BaseSubscriber<>() {}; operator.subscribe(subscriber); subscriber.cancel(); diff --git a/spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java b/spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java index e9d6bd1da38..3a361737fea 100644 --- a/spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/HttpMessageConverterExtractorTests.java @@ -153,7 +153,7 @@ class HttpMessageConverterExtractorTests { void generics() throws IOException { responseHeaders.setContentType(contentType); String expected = "Foo"; - ParameterizedTypeReference> reference = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> reference = new ParameterizedTypeReference<>() {}; Type type = reference.getType(); GenericHttpMessageConverter converter = mock(GenericHttpMessageConverter.class); diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java index e2a46d5919e..d8b0648680e 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java @@ -115,8 +115,7 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests { */ @RegisterExtension TestExecutionExceptionHandler serverErrorToAssertionErrorConverter = (context, throwable) -> { - if (throwable instanceof HttpServerErrorException) { - HttpServerErrorException ex = (HttpServerErrorException) throwable; + if (throwable instanceof HttpServerErrorException ex) { String responseBody = ex.getResponseBodyAsString(); String prefix = AssertionError.class.getName() + ": "; if (responseBody.startsWith(prefix)) { diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java index 85144efdeda..2f8fb82c4e9 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java @@ -646,7 +646,7 @@ class RestTemplateTests { void exchangeParameterizedType() throws Exception { GenericHttpMessageConverter converter = mock(GenericHttpMessageConverter.class); template.setMessageConverters(Collections.>singletonList(converter)); - ParameterizedTypeReference> intList = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> intList = new ParameterizedTypeReference<>() {}; given(converter.canRead(intList.getType(), null, null)).willReturn(true); given(converter.getSupportedMediaTypes(any())).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN)); given(converter.canWrite(String.class, String.class, null)).willReturn(true); diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/bootstrap/AbstractHttpHandlerIntegrationTests.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/bootstrap/AbstractHttpHandlerIntegrationTests.java index 90d05db9f20..1cb2ccf97f7 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/bootstrap/AbstractHttpHandlerIntegrationTests.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/bootstrap/AbstractHttpHandlerIntegrationTests.java @@ -52,8 +52,7 @@ public abstract class AbstractHttpHandlerIntegrationTests { */ @RegisterExtension TestExecutionExceptionHandler serverErrorToAssertionErrorConverter = (context, throwable) -> { - if (throwable instanceof HttpServerErrorException) { - HttpServerErrorException ex = (HttpServerErrorException) throwable; + if (throwable instanceof HttpServerErrorException ex) { String responseBody = ex.getResponseBodyAsString(); if (StringUtils.hasText(responseBody)) { String prefix = AssertionError.class.getName() + ": "; diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletRequest.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletRequest.java index 4fa2620ca84..1eb76b1f5ae 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletRequest.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletRequest.java @@ -1282,8 +1282,7 @@ public class MockHttpServletRequest implements HttpServletRequest { public void setSession(HttpSession session) { this.session = session; - if (session instanceof MockHttpSession) { - MockHttpSession mockSession = ((MockHttpSession) session); + if (session instanceof MockHttpSession mockSession) { mockSession.access(); } } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java index af9773ce330..267b6087393 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java @@ -447,8 +447,7 @@ public class MockHttpServletResponse implements HttpServletResponse { if (cookie.isHttpOnly()) { buf.append("; HttpOnly"); } - if (cookie instanceof MockCookie) { - MockCookie mockCookie = (MockCookie) cookie; + if (cookie instanceof MockCookie mockCookie) { if (StringUtils.hasText(mockCookie.getSameSite())) { buf.append("; SameSite=").append(mockCookie.getSameSite()); } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/xml/Pojo.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/xml/Pojo.java index 87487adebc7..e7bb736c01f 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/xml/Pojo.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/xml/Pojo.java @@ -57,8 +57,7 @@ public class Pojo { if (this == o) { return true; } - if (o instanceof Pojo) { - Pojo other = (Pojo) o; + if (o instanceof Pojo other) { return this.foo.equals(other.foo) && this.bar.equals(other.bar); } return false; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilderTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilderTests.java index 5bff972bdd2..14521cbac40 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilderTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilderTests.java @@ -202,7 +202,7 @@ public class DefaultClientRequestBuilderTests { public void bodyParameterizedTypeReference() { String body = "foo"; Publisher publisher = Mono.just(body); - ParameterizedTypeReference typeReference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference typeReference = new ParameterizedTypeReference<>() {}; ClientRequest result = ClientRequest.create(POST, DEFAULT_URL).body(publisher, typeReference).build(); List> messageWriters = new ArrayList<>(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/support/ClientResponseWrapperTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/support/ClientResponseWrapperTests.java index 5e7d13008cc..0031134b417 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/support/ClientResponseWrapperTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/support/ClientResponseWrapperTests.java @@ -111,7 +111,7 @@ public class ClientResponseWrapperTests { @Test public void bodyToMonoParameterizedTypeReference() { Mono result = Mono.just("foo"); - ParameterizedTypeReference reference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference reference = new ParameterizedTypeReference<>() {}; given(mockResponse.bodyToMono(reference)).willReturn(result); assertThat(wrapper.bodyToMono(reference)).isSameAs(result); @@ -128,7 +128,7 @@ public class ClientResponseWrapperTests { @Test public void bodyToFluxParameterizedTypeReference() { Flux result = Flux.just("foo"); - ParameterizedTypeReference reference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference reference = new ParameterizedTypeReference<>() {}; given(mockResponse.bodyToFlux(reference)).willReturn(result); assertThat(wrapper.bodyToFlux(reference)).isSameAs(result); @@ -145,7 +145,7 @@ public class ClientResponseWrapperTests { @Test public void toEntityParameterizedTypeReference() { Mono> result = Mono.just(new ResponseEntity<>("foo", HttpStatus.OK)); - ParameterizedTypeReference reference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference reference = new ParameterizedTypeReference<>() {}; given(mockResponse.toEntity(reference)).willReturn(result); assertThat(wrapper.toEntity(reference)).isSameAs(result); @@ -162,7 +162,7 @@ public class ClientResponseWrapperTests { @Test public void toEntityListParameterizedTypeReference() { Mono>> result = Mono.just(new ResponseEntity<>(singletonList("foo"), HttpStatus.OK)); - ParameterizedTypeReference reference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference reference = new ParameterizedTypeReference<>() {}; given(mockResponse.toEntityList(reference)).willReturn(result); assertThat(wrapper.toEntityList(reference)).isSameAs(result); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilderTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilderTests.java index 1e180ccfb04..87bb8145de7 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilderTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilderTests.java @@ -71,7 +71,7 @@ public class DefaultEntityResponseBuilderTests { @Test public void fromPublisher() { Flux body = Flux.just("foo", "bar"); - ParameterizedTypeReference typeReference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference typeReference = new ParameterizedTypeReference<>() {}; EntityResponse> response = EntityResponse.fromPublisher(body, typeReference).build().block(); assertThat(response.entity()).isSameAs(body); } @@ -79,7 +79,7 @@ public class DefaultEntityResponseBuilderTests { @Test public void fromProducer() { Single body = Single.just("foo"); - ParameterizedTypeReference typeReference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference typeReference = new ParameterizedTypeReference<>() {}; EntityResponse> response = EntityResponse.fromProducer(body, typeReference).build().block(); assertThat(response.entity()).isSameAs(body); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java index d195f1f12fa..65df3a89b21 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java @@ -288,7 +288,7 @@ public class DefaultServerRequestTests { .body(body); DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders); - ParameterizedTypeReference typeReference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference typeReference = new ParameterizedTypeReference<>() {}; Mono resultMono = request.bodyToMono(typeReference); assertThat(resultMono.block()).isEqualTo("foo"); } @@ -346,7 +346,7 @@ public class DefaultServerRequestTests { .body(body); DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders); - ParameterizedTypeReference typeReference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference typeReference = new ParameterizedTypeReference<>() {}; Flux resultFlux = request.bodyToFlux(typeReference); assertThat(resultFlux.collectList().block()).isEqualTo(Collections.singletonList("foo")); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java index 3bc9716124a..e80053a0ea7 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java @@ -88,7 +88,7 @@ class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTe void flux(HttpServer httpServer) throws Exception { startServer(httpServer); - ParameterizedTypeReference> reference = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> reference = new ParameterizedTypeReference<>() {}; ResponseEntity> result = this.restTemplate .exchange("http://localhost:" + this.port + "/flux", HttpMethod.GET, null, reference); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/PublisherHandlerFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/PublisherHandlerFunctionIntegrationTests.java index b34685ea563..02e47f48a93 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/PublisherHandlerFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/PublisherHandlerFunctionIntegrationTests.java @@ -69,7 +69,7 @@ class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunctionInt void flux(HttpServer httpServer) throws Exception { startServer(httpServer); - ParameterizedTypeReference> reference = new ParameterizedTypeReference>() {}; + ParameterizedTypeReference> reference = new ParameterizedTypeReference<>() {}; ResponseEntity> result = restTemplate.exchange("http://localhost:" + super.port + "/flux", HttpMethod.GET, null, reference); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapperTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapperTests.java index fe2c8d120f8..7ad2f447ad5 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapperTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapperTests.java @@ -159,7 +159,7 @@ public class ServerRequestWrapperTests { @Test public void bodyToMonoParameterizedTypeReference() { Mono result = Mono.just("foo"); - ParameterizedTypeReference reference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference reference = new ParameterizedTypeReference<>() {}; given(mockRequest.bodyToMono(reference)).willReturn(result); assertThat(wrapper.bodyToMono(reference)).isSameAs(result); @@ -176,7 +176,7 @@ public class ServerRequestWrapperTests { @Test public void bodyToFluxParameterizedTypeReference() { Flux result = Flux.just("foo"); - ParameterizedTypeReference reference = new ParameterizedTypeReference() {}; + ParameterizedTypeReference reference = new ParameterizedTypeReference<>() {}; given(mockRequest.bodyToFlux(reference)).willReturn(result); assertThat(wrapper.bodyToFlux(reference)).isSameAs(result); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java index 9a5f7302166..59fc87fcad3 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java @@ -353,8 +353,7 @@ public class MessageReaderArgumentResolverTests { if (this == o) { return true; } - if (o instanceof TestBean) { - TestBean other = (TestBean) o; + if (o instanceof TestBean other) { return this.foo.equals(other.foo) && this.bar.equals(other.bar); } return false; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java index e97d9b03b43..4a12bbc5074 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java @@ -71,7 +71,7 @@ import static org.springframework.http.MediaType.APPLICATION_XML; public class RequestMappingMessageConversionIntegrationTests extends AbstractRequestMappingIntegrationTests { private static final ParameterizedTypeReference> PERSON_LIST = - new ParameterizedTypeReference>() {}; + new ParameterizedTypeReference<>() {}; private static final MediaType JSON = MediaType.APPLICATION_JSON; diff --git a/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java b/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java index 1bec3cd01aa..d6bed9d7d8b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java @@ -347,7 +347,7 @@ class ContextLoaderTests { @Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); - environment.getPropertySources().addFirst(new PropertySource("testPropertySource") { + environment.getPropertySources().addFirst(new PropertySource<>("testPropertySource") { @Override public Object getProperty(String key) { return "name".equals(key) ? "testName" : null; diff --git a/spring-webmvc/src/test/java/org/springframework/web/context/XmlWebApplicationContextTests.java b/spring-webmvc/src/test/java/org/springframework/web/context/XmlWebApplicationContextTests.java index 837bb1c78c6..d0ce3e8d8fe 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/context/XmlWebApplicationContextTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/context/XmlWebApplicationContextTests.java @@ -56,8 +56,8 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes root.addBeanFactoryPostProcessor(beanFactory -> beanFactory.addBeanPostProcessor(new BeanPostProcessor() { @Override public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException { - if (bean instanceof TestBean) { - ((TestBean) bean).getFriends().add("myFriend"); + if (bean instanceof TestBean testBean) { + testBean.getFriends().add("myFriend"); } return bean; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java index d4bd763d6f6..803cb81af05 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java @@ -182,8 +182,7 @@ public class InterceptorRegistryTests { PathMatcher pathMatcher = new AntPathMatcher(); List result = new ArrayList<>(); for (Object interceptor : this.registry.getInterceptors()) { - if (interceptor instanceof MappedInterceptor) { - MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor; + if (interceptor instanceof MappedInterceptor mappedInterceptor) { if (mappedInterceptor.matches(lookupPath, pathMatcher)) { result.add(mappedInterceptor.getInterceptor()); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/i18n/LocaleResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/i18n/LocaleResolverTests.java index 1b8a24f644d..091f6596da7 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/i18n/LocaleResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/i18n/LocaleResolverTests.java @@ -83,8 +83,7 @@ public class LocaleResolverTests { } // check LocaleContext - if (localeResolver instanceof LocaleContextResolver) { - LocaleContextResolver localeContextResolver = (LocaleContextResolver) localeResolver; + if (localeResolver instanceof LocaleContextResolver localeContextResolver) { LocaleContext localeContext = localeContextResolver.resolveLocaleContext(request); if (shouldSet) { assertThat(localeContext.getLocale()).isEqualTo(Locale.GERMANY); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ItemPet.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ItemPet.java index 18d833cbb42..96ee51c0ba2 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ItemPet.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ItemPet.java @@ -46,10 +46,9 @@ public class ItemPet { if (this == other) { return true; } - if (!(other instanceof ItemPet)) { + if (!(other instanceof ItemPet otherPet)) { return false; } - ItemPet otherPet = (ItemPet) other; return (this.name != null && this.name.equals(otherPet.getName())); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/OptionTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/OptionTagTests.java index 608a62595e1..f96aeaddcbe 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/OptionTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/OptionTagTests.java @@ -556,8 +556,7 @@ class OptionTagTests extends AbstractHtmlElementTagTests { @Override public boolean equals(Object obj) { - if (obj instanceof RulesVariant) { - RulesVariant other = (RulesVariant) obj; + if (obj instanceof RulesVariant other) { return this.toId().equals(other.toId()); } return false; diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/UndertowTestServer.java b/spring-websocket/src/test/java/org/springframework/web/socket/UndertowTestServer.java index 914450bec2e..50f618eb8e8 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/UndertowTestServer.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/UndertowTestServer.java @@ -144,7 +144,7 @@ public class UndertowTestServer implements WebSocketTestServer { @Override public InstanceHandle createInstance() throws InstantiationException { - return new InstanceHandle() { + return new InstanceHandle<>() { @Override public Servlet getInstance() { return new DispatcherServlet(wac); @@ -167,7 +167,7 @@ public class UndertowTestServer implements WebSocketTestServer { @Override public InstanceHandle createInstance() throws InstantiationException { - return new InstanceHandle() { + return new InstanceHandle<>() { @Override public Filter getInstance() { return filter;