From 9d5881e0adbd9d6e13121f3d38efa8d35df66690 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 20 Jun 2020 16:42:36 +0200 Subject: [PATCH] Suppress warnings, remove unused code, etc. --- .../DefaultListableBeanFactoryTests.java | 65 +++++---- .../PropertiesBeanDefinitionReaderTests.java | 11 +- ...edBeansElementAttributeRecursionTests.java | 6 +- .../jdbc/core/JdbcTemplateTests.java | 4 +- .../jdbc/core/RowMapperTests.java | 3 +- .../oxm/AbstractUnmarshallerTests.java | 4 +- .../DelegatingConnectionFactoryUnitTests.java | 12 +- .../R2dbcTransactionManagerUnitTests.java | 39 +++-- .../SingleConnectionFactoryUnitTests.java | 38 +++-- ...nAwareConnectionFactoryProxyUnitTests.java | 21 +-- .../core/DefaultDatabaseClientUnitTests.java | 39 ++--- .../client/match/ContentRequestMatchers.java | 2 +- ...ithPropertiesExtendingPropertiesTests.java | 6 +- ...ltContextLoaderClassSpringRunnerTests.java | 6 +- ...sedSpringJUnit4ClassRunnerAppCtxTests.java | 6 +- ...bstractContextConfigurationUtilsTests.java | 8 +- .../BootstrapTestUtilsMergedConfigTests.java | 8 +- .../GenericPropertiesContextLoaderTests.java | 3 +- .../dao/support/DataAccessUtilsTests.java | 12 +- ...tationTransactionAttributeSourceTests.java | 3 +- ...AnnotationTransactionInterceptorTests.java | 5 +- .../http/codec/support/BaseDefaultCodecs.java | 1 + .../web/filter/ShallowEtagHeaderFilter.java | 10 -- .../http/ContentDispositionTests.java | 51 ++++--- .../http/HttpHeadersTests.java | 128 +++++++++-------- .../http/RequestEntityTests.java | 19 ++- .../AbstractAsyncHttpRequestFactoryTests.java | 4 +- .../AbstractHttpRequestFactoryTests.java | 2 +- .../codec/EncoderHttpMessageWriterTests.java | 7 - ...entNegotiationManagerFactoryBeanTests.java | 34 ++--- ...ensionContentNegotiationStrategyTests.java | 80 ++++------- .../web/client/RestTemplateTests.java | 136 ++++++++---------- .../client/WebClientIntegrationTests.java | 1 + .../servlet/ComplexWebApplicationContext.java | 6 +- .../servlet/SimpleWebApplicationContext.java | 4 +- ...tationDrivenBeanDefinitionParserTests.java | 3 +- .../web/servlet/config/MvcNamespaceTests.java | 1 + .../DelegatingWebMvcConfigurationTests.java | 2 + .../annotation/InterceptorRegistryTests.java | 3 +- ...MvcConfigurationSupportExtensionTests.java | 1 + .../function/DefaultServerRequestTests.java | 6 - .../handler/HandlerMethodMappingTests.java | 4 +- .../handler/SimpleUrlHandlerMappingTests.java | 1 + .../PatternsRequestConditionTests.java | 3 + ...RequestMappingInfoHandlerMappingTests.java | 1 + ...ndlerMethodMappingNamingStrategyTests.java | 9 +- .../method/annotation/CrossOriginTests.java | 1 + .../RequestMappingHandlerMappingTests.java | 8 +- .../ResourceHttpRequestHandlerTests.java | 2 + .../ContentNegotiatingViewResolverTests.java | 4 +- .../view/ResourceBundleViewResolverTests.java | 3 +- .../web/servlet/view/ViewResolverTests.java | 17 ++- .../StompWebSocketIntegrationTests.java | 14 +- 53 files changed, 418 insertions(+), 449 deletions(-) diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java index d6e50dc50a..63c5361229 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java @@ -74,7 +74,6 @@ import org.springframework.beans.factory.support.BeanDefinitionOverrideException import org.springframework.beans.factory.support.ChildBeanDefinition; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.ManagedList; -import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.ConstructorDependenciesBean; import org.springframework.beans.propertyeditors.CustomNumberEditor; @@ -139,7 +138,7 @@ class DefaultListableBeanFactoryTests { Properties p = new Properties(); p.setProperty("x1.(class)", KnowsIfInstantiated.class.getName()); assertThat(!KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isTrue(); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); lbf.preInstantiateSingletons(); assertThat(KnowsIfInstantiated.wasInstantiated()).as("singleton was instantiated").isTrue(); } @@ -151,7 +150,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("x1.(class)", KnowsIfInstantiated.class.getName()); p.setProperty("x1.(lazy-init)", "true"); assertThat(!KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isTrue(); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); assertThat(!KnowsIfInstantiated.wasInstantiated()).as("singleton not instantiated").isTrue(); lbf.preInstantiateSingletons(); @@ -168,7 +167,7 @@ class DefaultListableBeanFactoryTests { DummyFactory.reset(); p.setProperty("x1.singleton", "false"); assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue(); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue(); assertThat(lbf.getType("x1")).isEqualTo(TestBean.class); lbf.preInstantiateSingletons(); @@ -189,7 +188,7 @@ class DefaultListableBeanFactoryTests { DummyFactory.reset(); p.setProperty("x1.(singleton)", "false"); p.setProperty("x1.singleton", "false"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue(); String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false); @@ -223,7 +222,7 @@ class DefaultListableBeanFactoryTests { DummyFactory.reset(); p.setProperty("x1.(singleton)", "false"); p.setProperty("x1.singleton", "true"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue(); String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false); @@ -256,7 +255,7 @@ class DefaultListableBeanFactoryTests { // Reset static state DummyFactory.reset(); p.setProperty("x1.singleton", "false"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue(); String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false); @@ -289,7 +288,7 @@ class DefaultListableBeanFactoryTests { // Reset static state DummyFactory.reset(); p.setProperty("x1.singleton", "false"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); lbf.preInstantiateSingletons(); assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue(); @@ -483,7 +482,7 @@ class DefaultListableBeanFactoryTests { @Test void emptyPropertiesPopulation() { Properties p = new Properties(); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); assertThat(lbf.getBeanDefinitionCount() == 0).as("No beans defined after ignorable invalid").isTrue(); } @@ -492,7 +491,7 @@ class DefaultListableBeanFactoryTests { Properties p = new Properties(); p.setProperty("foo", "bar"); p.setProperty("qwert", "er"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p, "test"); + registerBeanDefinitions(p, "test"); assertThat(lbf.getBeanDefinitionCount() == 0).as("No beans defined after harmless ignorable rubbish").isTrue(); } @@ -502,7 +501,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("test.(class)", TestBean.class.getName()); p.setProperty("test.name", "Tony"); p.setProperty("test.age", "48"); - int count = (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + int count = registerBeanDefinitions(p); assertThat(count == 1).as("1 beans registered, not " + count).isTrue(); singleTestBean(lbf); } @@ -514,7 +513,7 @@ class DefaultListableBeanFactoryTests { p.setProperty(PREFIX + "test.(class)", TestBean.class.getName()); p.setProperty(PREFIX + "test.name", "Tony"); p.setProperty(PREFIX + "test.age", "0x30"); - int count = (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p, PREFIX); + int count = registerBeanDefinitions(p, PREFIX); assertThat(count == 1).as("1 beans registered, not " + count).isTrue(); singleTestBean(lbf); } @@ -532,7 +531,7 @@ class DefaultListableBeanFactoryTests { p.setProperty(PREFIX + "kerry.age", "35"); p.setProperty(PREFIX + "kerry.spouse(ref)", "rod"); - int count = (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p, PREFIX); + int count = registerBeanDefinitions(p, PREFIX); assertThat(count == 2).as("2 beans registered, not " + count).isTrue(); TestBean kerry = lbf.getBean("kerry", TestBean.class); @@ -549,7 +548,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("tb.(class)", TestBean.class.getName()); p.setProperty("tb.someMap[my.key]", "my.value"); - int count = (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + int count = registerBeanDefinitions(p); assertThat(count == 1).as("1 beans registered, not " + count).isTrue(); assertThat(lbf.getBeanDefinitionCount()).isEqualTo(1); @@ -567,7 +566,7 @@ class DefaultListableBeanFactoryTests { p.setProperty(PREFIX + "kerry.age", "35"); p.setProperty(PREFIX + "kerry.spouse(ref)", "rod"); - new PropertiesBeanDefinitionReader(lbf).registerBeanDefinitions(p, PREFIX); + registerBeanDefinitions(p, PREFIX); assertThatExceptionOfType(BeansException.class).as("unresolved reference").isThrownBy(() -> lbf.getBean("kerry")); } @@ -690,7 +689,7 @@ class DefaultListableBeanFactoryTests { Properties p = new Properties(); p.setProperty("kerry.(class)", TestBean.class.getName()); p.setProperty("kerry.age", "35"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); TestBean kerry1 = (TestBean) lbf.getBean("kerry"); TestBean kerry2 = (TestBean) lbf.getBean("kerry"); assertThat(kerry1 != null).as("Non null").isTrue(); @@ -701,7 +700,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("kerry.(class)", TestBean.class.getName()); p.setProperty("kerry.(scope)", "prototype"); p.setProperty("kerry.age", "35"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); kerry1 = (TestBean) lbf.getBean("kerry"); kerry2 = (TestBean) lbf.getBean("kerry"); assertThat(kerry1 != null).as("Non null").isTrue(); @@ -712,7 +711,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("kerry.(class)", TestBean.class.getName()); p.setProperty("kerry.(scope)", "singleton"); p.setProperty("kerry.age", "35"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); kerry1 = (TestBean) lbf.getBean("kerry"); kerry2 = (TestBean) lbf.getBean("kerry"); assertThat(kerry1 != null).as("Non null").isTrue(); @@ -731,7 +730,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("rod.age", "34"); p.setProperty("rod.spouse", "*kerry"); - new PropertiesBeanDefinitionReader(lbf).registerBeanDefinitions(p); + registerBeanDefinitions(p); assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> lbf.getBean("kerry")) .satisfies(ex -> assertThat(ex.contains(BeanCurrentlyInCreationException.class)).isTrue()); @@ -745,7 +744,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("kerry.(parent)", "wife"); p.setProperty("kerry.age", "35"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); TestBean kerry1 = (TestBean) lbf.getBean("kerry"); TestBean kerry2 = (TestBean) lbf.getBean("kerry"); assertThat(kerry1.getName()).isEqualTo("kerry"); @@ -760,7 +759,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("kerry.(parent)", "wife"); p.setProperty("kerry.(singleton)", "false"); p.setProperty("kerry.age", "35"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); assertThat(lbf.isSingleton("kerry")).isFalse(); kerry1 = (TestBean) lbf.getBean("kerry"); kerry2 = (TestBean) lbf.getBean("kerry"); @@ -772,7 +771,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("kerry.(class)", TestBean.class.getName()); p.setProperty("kerry.(singleton)", "true"); p.setProperty("kerry.age", "35"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); kerry1 = (TestBean) lbf.getBean("kerry"); kerry2 = (TestBean) lbf.getBean("kerry"); assertThat(kerry1 != null).as("Non null").isTrue(); @@ -823,9 +822,9 @@ class DefaultListableBeanFactoryTests { Properties p = new Properties(); p.setProperty("kerry.(class)", TestBean.class.getName()); p.setProperty("kerry.age", "35"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); try { - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); } catch (BeanDefinitionStoreException ex) { assertThat(ex.getBeanName()).isEqualTo("kerry"); @@ -965,7 +964,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("k.(class)", TestBean.class.getName()); p.setProperty("k.name", "kerry"); p.setProperty("k.spouse", "*r"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); TestBean k = (TestBean) lbf.getBean("k"); TestBean r = (TestBean) lbf.getBean("r"); assertThat(k.getSpouse() == r).isTrue(); @@ -977,7 +976,7 @@ class DefaultListableBeanFactoryTests { Properties p = new Properties(); p.setProperty("r.(class)", TestBean.class.getName()); p.setProperty("r.name", "*" + name); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); TestBean r = (TestBean) lbf.getBean("r"); assertThat(r.getName().equals(name)).isTrue(); } @@ -1081,7 +1080,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("test.name", "Tony"); p.setProperty("test.age", "48"); p.setProperty("test.spouse(ref)", "singletonObject"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); Object singletonObject = new TestBean(); lbf.registerSingleton("singletonObject", singletonObject); @@ -1117,7 +1116,7 @@ class DefaultListableBeanFactoryTests { p.setProperty("test.name", "Tony"); p.setProperty("test.age", "48"); p.setProperty("test.spouse(ref)", "singletonObject"); - (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + registerBeanDefinitions(p); lbf.registerBeanDefinition("singletonObject", new RootBeanDefinition(PropertiesFactoryBean.class)); Object singletonObject = new TestBean(); lbf.registerSingleton("singletonObject", singletonObject); @@ -2895,6 +2894,16 @@ class DefaultListableBeanFactoryTests { } } + @SuppressWarnings("deprecation") + private int registerBeanDefinitions(Properties p) { + return (new org.springframework.beans.factory.support.PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p); + } + + @SuppressWarnings("deprecation") + private int registerBeanDefinitions(Properties p, String prefix) { + return (new org.springframework.beans.factory.support.PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p, prefix); + } + static class A { } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReaderTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReaderTests.java index dbb70e54b9..d7df748c5c 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReaderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -26,7 +26,8 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Rob Harrop */ -public class PropertiesBeanDefinitionReaderTests { +@SuppressWarnings("deprecation") +class PropertiesBeanDefinitionReaderTests { private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @@ -34,14 +35,14 @@ public class PropertiesBeanDefinitionReaderTests { @Test - public void withSimpleConstructorArg() { + void withSimpleConstructorArg() { this.reader.loadBeanDefinitions(new ClassPathResource("simpleConstructorArg.properties", getClass())); TestBean bean = (TestBean) this.beanFactory.getBean("testBean"); assertThat(bean.getName()).isEqualTo("Rob Harrop"); } @Test - public void withConstructorArgRef() { + void withConstructorArgRef() { this.reader.loadBeanDefinitions(new ClassPathResource("refConstructorArg.properties", getClass())); TestBean rob = (TestBean) this.beanFactory.getBean("rob"); TestBean sally = (TestBean) this.beanFactory.getBean("sally"); @@ -49,7 +50,7 @@ public class PropertiesBeanDefinitionReaderTests { } @Test - public void withMultipleConstructorsArgs() { + void withMultipleConstructorsArgs() { this.reader.loadBeanDefinitions(new ClassPathResource("multiConstructorArgs.properties", getClass())); TestBean bean = (TestBean) this.beanFactory.getBean("testBean"); assertThat(bean.getName()).isEqualTo("Rob Harrop"); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementAttributeRecursionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementAttributeRecursionTests.java index debeb353ca..cce3bb3ca1 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementAttributeRecursionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementAttributeRecursionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -25,8 +25,6 @@ import org.springframework.core.io.ClassPathResource; import static org.assertj.core.api.Assertions.assertThat; - - /** * Tests for propagating enclosing beans element defaults to nested beans elements. * @@ -69,7 +67,6 @@ public class NestedBeansElementAttributeRecursionTests { } @Test - @SuppressWarnings("unchecked") public void defaultMerge() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( @@ -79,7 +76,6 @@ public class NestedBeansElementAttributeRecursionTests { } @Test - @SuppressWarnings("unchecked") public void defaultMergeWithNonValidatingParser() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(bf); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java index 25f84cb089..8441317e53 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -175,12 +175,14 @@ public class JdbcTemplateTests { } @Test + @SuppressWarnings("deprecation") public void testStringsWithEmptyPreparedStatementArgs() throws Exception { doTestStrings(null, null, null, null, (template, sql, rch) -> template.query(sql, (Object[]) null, rch)); } @Test + @SuppressWarnings("deprecation") public void testStringsWithPreparedStatementArgs() throws Exception { final Integer argument = 99; doTestStrings(null, null, null, argument, diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java index dd849029b9..22896c2d1a 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/RowMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -112,6 +112,7 @@ public class RowMapperTests { } @Test + @SuppressWarnings("deprecation") public void queryWithArgsAndRowMapper() throws SQLException { result = template.query("some SQL", new Object[] { "test1", "test2" }, testRowMapper); preparedStatement.setString(1, "test1"); diff --git a/spring-oxm/src/test/java/org/springframework/oxm/AbstractUnmarshallerTests.java b/spring-oxm/src/test/java/org/springframework/oxm/AbstractUnmarshallerTests.java index 8433cce73b..9f0eb47435 100644 --- a/spring-oxm/src/test/java/org/springframework/oxm/AbstractUnmarshallerTests.java +++ b/spring-oxm/src/test/java/org/springframework/oxm/AbstractUnmarshallerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -98,7 +98,7 @@ public abstract class AbstractUnmarshallerTests { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings("deprecation") // on JDK 9 public void unmarshalSAXSource() throws Exception { XMLReader reader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); SAXSource source = new SAXSource(reader, new InputSource(new StringReader(INPUT_STRING))); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java index f6c7ca0fbd..fb7e6fa9e1 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/DelegatingConnectionFactoryUnitTests.java @@ -30,18 +30,18 @@ import static org.mockito.BDDMockito.when; * * @author Mark Paluch */ -public class DelegatingConnectionFactoryUnitTests { +class DelegatingConnectionFactoryUnitTests { ConnectionFactory delegate = mock(ConnectionFactory.class); Connection connectionMock = mock(Connection.class); - DelegatingConnectionFactory connectionFactory = new ExampleConnectionFactory( - delegate); + DelegatingConnectionFactory connectionFactory = new ExampleConnectionFactory(delegate); + @Test - public void shouldDelegateGetConnection() { - + @SuppressWarnings({ "rawtypes", "unchecked" }) + void shouldDelegateGetConnection() { Mono connectionMono = Mono.just(connectionMock); when(delegate.create()).thenReturn((Mono) connectionMono); @@ -49,7 +49,7 @@ public class DelegatingConnectionFactoryUnitTests { } @Test - public void shouldDelegateUnwrapWithoutImplementing() { + void shouldDelegateUnwrapWithoutImplementing() { assertThat(connectionFactory.unwrap()).isSameAs(delegate); } diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java index 3003b1a354..fa3d7d6db3 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/R2dbcTransactionManagerUnitTests.java @@ -53,7 +53,7 @@ import static org.mockito.BDDMockito.when; * * @author Mark Paluch */ -public class R2dbcTransactionManagerUnitTests { +class R2dbcTransactionManagerUnitTests { ConnectionFactory connectionFactoryMock = mock(ConnectionFactory.class); @@ -62,8 +62,8 @@ public class R2dbcTransactionManagerUnitTests { private R2dbcTransactionManager tm; @BeforeEach - public void before() { - + @SuppressWarnings({ "unchecked", "rawtypes" }) + void before() { when(connectionFactoryMock.create()).thenReturn((Mono) Mono.just(connectionMock)); when(connectionMock.beginTransaction()).thenReturn(Mono.empty()); when(connectionMock.close()).thenReturn(Mono.empty()); @@ -71,7 +71,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void testSimpleTransaction() { + void testSimpleTransaction() { TestTransactionSynchronization sync = new TestTransactionSynchronization( TransactionSynchronization.STATUS_COMMITTED); AtomicInteger commits = new AtomicInteger(); @@ -103,7 +103,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void testBeginFails() { + void testBeginFails() { reset(connectionFactoryMock); when(connectionFactoryMock.create()).thenReturn( Mono.error(new R2dbcBadGrammarException("fail"))); @@ -125,7 +125,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void appliesIsolationLevel() { + void appliesIsolationLevel() { when(connectionMock.commitTransaction()).thenReturn(Mono.empty()); when(connectionMock.getTransactionIsolationLevel()).thenReturn( IsolationLevel.READ_COMMITTED); @@ -151,7 +151,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void doesNotSetIsolationLevelIfMatch() { + void doesNotSetIsolationLevelIfMatch() { when(connectionMock.getTransactionIsolationLevel()).thenReturn( IsolationLevel.READ_COMMITTED); when(connectionMock.commitTransaction()).thenReturn(Mono.empty()); @@ -173,7 +173,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void doesNotSetAutoCommitDisabled() { + void doesNotSetAutoCommitDisabled() { when(connectionMock.isAutoCommit()).thenReturn(false); when(connectionMock.commitTransaction()).thenReturn(Mono.empty()); @@ -193,7 +193,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void restoresAutoCommit() { + void restoresAutoCommit() { when(connectionMock.isAutoCommit()).thenReturn(true); when(connectionMock.setAutoCommit(anyBoolean())).thenReturn(Mono.empty()); when(connectionMock.commitTransaction()).thenReturn(Mono.empty()); @@ -216,7 +216,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void appliesReadOnly() { + void appliesReadOnly() { when(connectionMock.commitTransaction()).thenReturn(Mono.empty()); when(connectionMock.setTransactionIsolationLevel(any())).thenReturn(Mono.empty()); Statement statement = mock(Statement.class); @@ -244,7 +244,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void testCommitFails() { + void testCommitFails() { when(connectionMock.commitTransaction()).thenReturn(Mono.defer(() -> Mono.error(new R2dbcBadGrammarException("Commit should fail")))); when(connectionMock.rollbackTransaction()).thenReturn(Mono.empty()); @@ -266,7 +266,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void testRollback() { + void testRollback() { AtomicInteger commits = new AtomicInteger(); when(connectionMock.commitTransaction()).thenReturn( @@ -295,7 +295,8 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void testRollbackFails() { + @SuppressWarnings("unchecked") + void testRollbackFails() { when(connectionMock.rollbackTransaction()).thenReturn(Mono.defer(() -> Mono.error(new R2dbcBadGrammarException("Commit should fail"))), Mono.empty()); TransactionalOperator operator = TransactionalOperator.create(tm); @@ -319,7 +320,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void testTransactionSetRollbackOnly() { + void testTransactionSetRollbackOnly() { when(connectionMock.rollbackTransaction()).thenReturn(Mono.empty()); TestTransactionSynchronization sync = new TestTransactionSynchronization( TransactionSynchronization.STATUS_ROLLED_BACK); @@ -352,7 +353,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void testPropagationNeverWithExistingTransaction() { + void testPropagationNeverWithExistingTransaction() { when(connectionMock.rollbackTransaction()).thenReturn(Mono.empty()); DefaultTransactionDefinition definition = new DefaultTransactionDefinition(); @@ -377,7 +378,7 @@ public class R2dbcTransactionManagerUnitTests { } @Test - public void testPropagationSupportsAndRequiresNew() { + void testPropagationSupportsAndRequiresNew() { when(connectionMock.commitTransaction()).thenReturn(Mono.empty()); DefaultTransactionDefinition definition = new DefaultTransactionDefinition(); @@ -419,9 +420,7 @@ public class R2dbcTransactionManagerUnitTests { public boolean afterCompletionCalled; - public Throwable afterCompletionException; - - public TestTransactionSynchronization(int status) { + TestTransactionSynchronization(int status) { this.status = status; } @@ -471,7 +470,7 @@ public class R2dbcTransactionManagerUnitTests { return Mono.fromRunnable(() -> doAfterCompletion(status)); } catch (Throwable ex) { - this.afterCompletionException = ex; + // ignore } return Mono.empty(); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java index dd8344935d..98b98a7843 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/SingleConnectionFactoryUnitTests.java @@ -37,12 +37,11 @@ import static org.mockito.BDDMockito.when; * * @author Mark Paluch */ -public class SingleConnectionFactoryUnitTests { +class SingleConnectionFactoryUnitTests { @Test - public void shouldAllocateSameConnection() { - SingleConnectionFactory factory = new SingleConnectionFactory( - "r2dbc:h2:mem:///foo", false); + void shouldAllocateSameConnection() { + SingleConnectionFactory factory = new SingleConnectionFactory("r2dbc:h2:mem:///foo", false); Mono cf1 = factory.create(); Mono cf2 = factory.create(); @@ -55,9 +54,8 @@ public class SingleConnectionFactoryUnitTests { } @Test - public void shouldApplyAutoCommit() { - SingleConnectionFactory factory = new SingleConnectionFactory( - "r2dbc:h2:mem:///foo", false); + void shouldApplyAutoCommit() { + SingleConnectionFactory factory = new SingleConnectionFactory("r2dbc:h2:mem:///foo", false); factory.setAutoCommit(false); factory.create().as(StepVerifier::create) @@ -74,9 +72,9 @@ public class SingleConnectionFactoryUnitTests { } @Test - public void shouldSuppressClose() { - SingleConnectionFactory factory = new SingleConnectionFactory( - "r2dbc:h2:mem:///foo", true); + @SuppressWarnings("rawtypes") + void shouldSuppressClose() { + SingleConnectionFactory factory = new SingleConnectionFactory("r2dbc:h2:mem:///foo", true); Connection connection = factory.create().block(); @@ -91,27 +89,24 @@ public class SingleConnectionFactoryUnitTests { } @Test - public void shouldNotSuppressClose() { - SingleConnectionFactory factory = new SingleConnectionFactory( - "r2dbc:h2:mem:///foo", false); + void shouldNotSuppressClose() { + SingleConnectionFactory factory = new SingleConnectionFactory("r2dbc:h2:mem:///foo", false); Connection connection = factory.create().block(); StepVerifier.create(connection.close()).verifyComplete(); - StepVerifier.create(connection.setTransactionIsolationLevel( - IsolationLevel.READ_COMMITTED)).verifyError( - R2dbcNonTransientResourceException.class); + StepVerifier.create(connection.setTransactionIsolationLevel(IsolationLevel.READ_COMMITTED)) + .verifyError(R2dbcNonTransientResourceException.class); factory.destroy(); } @Test - public void releaseConnectionShouldNotCloseConnection() { + void releaseConnectionShouldNotCloseConnection() { Connection connectionMock = mock(Connection.class); ConnectionFactoryMetadata metadata = mock(ConnectionFactoryMetadata.class); - SingleConnectionFactory factory = new SingleConnectionFactory( - connectionMock, metadata, true); + SingleConnectionFactory factory = new SingleConnectionFactory(connectionMock, metadata, true); Connection connection = factory.create().block(); @@ -123,14 +118,13 @@ public class SingleConnectionFactoryUnitTests { } @Test - public void releaseConnectionShouldCloseUnrelatedConnection() { + void releaseConnectionShouldCloseUnrelatedConnection() { Connection connectionMock = mock(Connection.class); Connection otherConnection = mock(Connection.class); ConnectionFactoryMetadata metadata = mock(ConnectionFactoryMetadata.class); when(otherConnection.close()).thenReturn(Mono.empty()); - SingleConnectionFactory factory = new SingleConnectionFactory( - connectionMock, metadata, false); + SingleConnectionFactory factory = new SingleConnectionFactory(connectionMock, metadata, false); factory.create().as(StepVerifier::create).expectNextCount(1).verifyComplete(); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java index 0cc83b51db..83a0d13e94 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxyUnitTests.java @@ -42,7 +42,7 @@ import static org.mockito.BDDMockito.when; * @author Mark Paluch * @author Christoph Strobl */ -public class TransactionAwareConnectionFactoryProxyUnitTests { +class TransactionAwareConnectionFactoryProxyUnitTests { ConnectionFactory connectionFactoryMock = mock(ConnectionFactory.class); @@ -55,14 +55,15 @@ public class TransactionAwareConnectionFactoryProxyUnitTests { R2dbcTransactionManager tm; @BeforeEach - public void before() { + @SuppressWarnings({ "rawtypes", "unchecked" }) + void before() { when(connectionFactoryMock.create()).thenReturn((Mono) Mono.just(connectionMock1), (Mono) Mono.just(connectionMock2), (Mono) Mono.just(connectionMock3)); tm = new R2dbcTransactionManager(connectionFactoryMock); } @Test - public void createShouldWrapConnection() { + void createShouldWrapConnection() { new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create() .as(StepVerifier::create) .consumeNextWith(connection -> assertThat(connection).isInstanceOf(Wrapped.class)) @@ -70,7 +71,7 @@ public class TransactionAwareConnectionFactoryProxyUnitTests { } @Test - public void unwrapShouldReturnTargetConnection() { + void unwrapShouldReturnTargetConnection() { new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create() .map(Wrapped.class::cast).as(StepVerifier::create) .consumeNextWith(wrapped -> assertThat(wrapped.unwrap()).isEqualTo(connectionMock1)) @@ -78,7 +79,7 @@ public class TransactionAwareConnectionFactoryProxyUnitTests { } @Test - public void unwrapShouldReturnTargetConnectionEvenWhenClosed() { + void unwrapShouldReturnTargetConnectionEvenWhenClosed() { when(connectionMock1.close()).thenReturn(Mono.empty()); new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create() @@ -90,7 +91,7 @@ public class TransactionAwareConnectionFactoryProxyUnitTests { } @Test - public void getTargetConnectionShouldReturnTargetConnection() { + void getTargetConnectionShouldReturnTargetConnection() { new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create() .map(Wrapped.class::cast).as(StepVerifier::create) .consumeNextWith(wrapped -> assertThat(wrapped.unwrap()).isEqualTo(connectionMock1)) @@ -98,7 +99,7 @@ public class TransactionAwareConnectionFactoryProxyUnitTests { } @Test - public void getMetadataShouldThrowsErrorEvenWhenClosed() { + void getMetadataShouldThrowsErrorEvenWhenClosed() { when(connectionMock1.close()).thenReturn(Mono.empty()); new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create() @@ -110,7 +111,7 @@ public class TransactionAwareConnectionFactoryProxyUnitTests { } @Test - public void hashCodeShouldReturnProxyHash() { + void hashCodeShouldReturnProxyHash() { new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create() .map(Connection.class::cast).as(StepVerifier::create) .consumeNextWith(connection -> assertThat(connection.hashCode()).isEqualTo( @@ -118,7 +119,7 @@ public class TransactionAwareConnectionFactoryProxyUnitTests { } @Test - public void equalsShouldCompareCorrectly() { + void equalsShouldCompareCorrectly() { new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create() .map(Connection.class::cast).as(StepVerifier::create) .consumeNextWith(connection -> { @@ -128,7 +129,7 @@ public class TransactionAwareConnectionFactoryProxyUnitTests { } @Test - public void shouldEmitBoundConnection() { + void shouldEmitBoundConnection() { when(connectionMock1.beginTransaction()).thenReturn(Mono.empty()); when(connectionMock1.commitTransaction()).thenReturn(Mono.empty()); when(connectionMock1.close()).thenReturn(Mono.empty()); diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java index 61f593b377..78e14e4211 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java @@ -66,7 +66,7 @@ import static org.mockito.BDDMockito.when; */ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) -public class DefaultDatabaseClientUnitTests { +class DefaultDatabaseClientUnitTests { @Mock Connection connection; @@ -74,7 +74,8 @@ public class DefaultDatabaseClientUnitTests { private DatabaseClient.Builder databaseClientBuilder; @BeforeEach - public void before() { + @SuppressWarnings({ "rawtypes", "unchecked" }) + void before() { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); when(connectionFactory.create()).thenReturn((Publisher) Mono.just(connection)); @@ -85,7 +86,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void shouldCloseConnectionOnlyOnce() { + void shouldCloseConnectionOnlyOnce() { DefaultDatabaseClient databaseClient = (DefaultDatabaseClient) databaseClientBuilder.build(); Flux flux = databaseClient.inConnectionMany(connection -> Flux.empty()); @@ -118,7 +119,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void executeShouldBindNullValues() { + void executeShouldBindNullValues() { Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1"); DatabaseClient databaseClient = databaseClientBuilder.namedParameters(false).build(); @@ -135,7 +136,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void executeShouldBindSettableValues() { + void executeShouldBindSettableValues() { Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1"); DatabaseClient databaseClient = databaseClientBuilder.namedParameters(false).build(); @@ -154,7 +155,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void executeShouldBindNamedNullValues() { + void executeShouldBindNamedNullValues() { Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1"); DatabaseClient databaseClient = databaseClientBuilder.build(); @@ -166,7 +167,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void executeShouldBindNamedValuesFromIndexes() { + void executeShouldBindNamedValuesFromIndexes() { Statement statement = mockStatementFor( "SELECT id, name, manual FROM legoset WHERE name IN ($1, $2, $3)"); @@ -185,7 +186,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void executeShouldBindValues() { + void executeShouldBindValues() { Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1"); DatabaseClient databaseClient = databaseClientBuilder.build(); @@ -202,7 +203,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void executeShouldBindNamedValuesByIndex() { + void executeShouldBindNamedValuesByIndex() { Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1"); DatabaseClient databaseClient = databaseClientBuilder.build(); @@ -214,11 +215,11 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void rowsUpdatedShouldEmitSingleValue() { + @SuppressWarnings("unchecked") + void rowsUpdatedShouldEmitSingleValue() { Result result = mock(Result.class); - when(result.getRowsUpdated()).thenReturn(Mono.empty(), Mono.just(2), - Flux.just(1, 2, 3)); + when(result.getRowsUpdated()).thenReturn(Mono.empty(), Mono.just(2), Flux.just(1, 2, 3)); mockStatementFor("DROP TABLE tab;", result); DatabaseClient databaseClient = databaseClientBuilder.build(); @@ -234,7 +235,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void selectShouldEmitFirstValue() { + void selectShouldEmitFirstValue() { MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata( MockColumnMetadata.builder().name("name").build()).build(); @@ -254,7 +255,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void selectShouldEmitAllValues() { + void selectShouldEmitAllValues() { MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata( MockColumnMetadata.builder().name("name").build()).build(); @@ -275,7 +276,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void selectOneShouldFailWithException() { + void selectOneShouldFailWithException() { MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata( MockColumnMetadata.builder().name("name").build()).build(); @@ -295,7 +296,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void shouldApplyExecuteFunction() { + void shouldApplyExecuteFunction() { Statement statement = mockStatement(); MockResult result = mockSingleColumnResult( @@ -311,7 +312,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void shouldApplyPreparedOperation() { + void shouldApplyPreparedOperation() { MockResult result = mockSingleColumnResult( MockRow.builder().identified(0, Object.class, "Walter")); @@ -342,7 +343,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void shouldApplyStatementFilterFunctions() { + void shouldApplyStatementFilterFunctions() { MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata( MockColumnMetadata.builder().name("name").build()).build(); @@ -366,7 +367,7 @@ public class DefaultDatabaseClientUnitTests { } @Test - public void shouldApplySimpleStatementFilterFunctions() { + void shouldApplySimpleStatementFilterFunctions() { MockResult result = mockSingleColumnEmptyResult(); diff --git a/spring-test/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java b/spring-test/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java index fe1762c4ee..ec883b02a4 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java @@ -240,7 +240,7 @@ public class ContentRequestMatchers { } else if (expected instanceof String) { assertTrue("Multipart is not a String", actual instanceof String); - assertEquals("Multipart content", expected, (String) actual); + assertEquals("Multipart content", expected, actual); } else { throw new IllegalArgumentException("Unexpected multipart value: " + expected.getClass()); diff --git a/spring-test/src/test/java/org/springframework/test/context/configuration/ContextConfigurationWithPropertiesExtendingPropertiesTests.java b/spring-test/src/test/java/org/springframework/test/context/configuration/ContextConfigurationWithPropertiesExtendingPropertiesTests.java index 1e6dd9f3ab..a76729668c 100644 --- a/spring-test/src/test/java/org/springframework/test/context/configuration/ContextConfigurationWithPropertiesExtendingPropertiesTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/configuration/ContextConfigurationWithPropertiesExtendingPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -23,7 +23,6 @@ import org.springframework.beans.testfixture.beans.Pet; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextLoader; import org.springframework.test.context.junit4.PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests; -import org.springframework.test.context.support.GenericPropertiesContextLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -38,7 +37,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @see PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests * @see ContextConfigurationWithPropertiesExtendingPropertiesAndInheritedLoaderTests */ -@ContextConfiguration(loader = GenericPropertiesContextLoader.class) +@SuppressWarnings("deprecation") +@ContextConfiguration(loader = org.springframework.test.context.support.GenericPropertiesContextLoader.class) public class ContextConfigurationWithPropertiesExtendingPropertiesTests extends PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests { diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/CustomDefaultContextLoaderClassSpringRunnerTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/CustomDefaultContextLoaderClassSpringRunnerTests.java index 64b0391b89..62a33fde0b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/CustomDefaultContextLoaderClassSpringRunnerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/CustomDefaultContextLoaderClassSpringRunnerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -25,7 +25,6 @@ import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextLoader; import org.springframework.test.context.support.DefaultTestContextBootstrapper; -import org.springframework.test.context.support.GenericPropertiesContextLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -62,8 +61,9 @@ public class CustomDefaultContextLoaderClassSpringRunnerTests { public static class PropertiesBasedTestContextBootstrapper extends DefaultTestContextBootstrapper { @Override + @SuppressWarnings("deprecation") protected Class getDefaultContextLoaderClass(Class testClass) { - return GenericPropertiesContextLoader.class; + return org.springframework.test.context.support.GenericPropertiesContextLoader.class; } } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests.java index 9dfacdea54..a9176f76de 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests.java @@ -25,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.testfixture.beans.Pet; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.support.GenericPropertiesContextLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -51,11 +50,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Sam Brannen * @since 2.5 - * @see GenericPropertiesContextLoader + * @see org.springframework.test.context.support.GenericPropertiesContextLoader * @see SpringJUnit4ClassRunnerAppCtxTests */ @RunWith(SpringRunner.class) -@ContextConfiguration(loader = GenericPropertiesContextLoader.class) +@SuppressWarnings("deprecation") +@ContextConfiguration(loader = org.springframework.test.context.support.GenericPropertiesContextLoader.class) public class PropertiesBasedSpringJUnit4ClassRunnerAppCtxTests { @Autowired diff --git a/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java index 27f00f3511..f4c843f90e 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -205,14 +205,16 @@ abstract class AbstractContextConfigurationUtilsTests { static class OverriddenClassesBar extends ClassesFoo { } - @ContextConfiguration(locations = "/foo.properties", loader = GenericPropertiesContextLoader.class) + @SuppressWarnings("deprecation") + @ContextConfiguration(locations = "/foo.properties", loader = org.springframework.test.context.support.GenericPropertiesContextLoader.class) @ActiveProfiles("foo") static class PropertiesLocationsFoo { } // Combining @Configuration classes with a Properties based loader doesn't really make // sense, but that's OK for unit testing purposes. - @ContextConfiguration(classes = FooConfig.class, loader = GenericPropertiesContextLoader.class) + @SuppressWarnings("deprecation") + @ContextConfiguration(classes = FooConfig.class, loader = org.springframework.test.context.support.GenericPropertiesContextLoader.class) @ActiveProfiles("foo") static class PropertiesClassesFoo { } diff --git a/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java index 21b2a8b3ba..c235e7f2ca 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -136,9 +136,10 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt } @Test + @SuppressWarnings("deprecation") void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndLocations() { Class testClass = PropertiesLocationsFoo.class; - Class expectedContextLoaderClass = GenericPropertiesContextLoader.class; + Class expectedContextLoaderClass = org.springframework.test.context.support.GenericPropertiesContextLoader.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); assertMergedConfig(mergedConfig, testClass, array("classpath:/foo.properties"), EMPTY_CLASS_ARRAY, @@ -146,9 +147,10 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt } @Test + @SuppressWarnings("deprecation") void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndClasses() { Class testClass = PropertiesClassesFoo.class; - Class expectedContextLoaderClass = GenericPropertiesContextLoader.class; + Class expectedContextLoaderClass = org.springframework.test.context.support.GenericPropertiesContextLoader.class; MergedContextConfiguration mergedConfig = buildMergedContextConfiguration(testClass); assertMergedConfig(mergedConfig, testClass, EMPTY_STRING_ARRAY, array(FooConfig.class), diff --git a/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java b/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java index 88492e8fb6..f502e75206 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/GenericPropertiesContextLoaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -28,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Sam Brannen * @since 4.0.4 */ +@SuppressWarnings("deprecation") class GenericPropertiesContextLoaderTests { private static final String[] EMPTY_STRING_ARRAY = new String[0]; diff --git a/spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java b/spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java index 8bf3d80876..8d5ac6e941 100644 --- a/spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java +++ b/spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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,6 +17,7 @@ package org.springframework.dao.support; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -119,14 +120,11 @@ public class DataAccessUtilsTests { } @Test - @SuppressWarnings("deprecation") // on JDK 9 public void withEquivalentIntegerInstanceTwice() { - Collection col = new ArrayList<>(2); - col.add(new Integer(5)); - col.add(new Integer(5)); + Collection col = Arrays.asList(Integer.valueOf(555), Integer.valueOf(555)); - assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() -> - DataAccessUtils.uniqueResult(col)) + assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class) + .isThrownBy(() -> DataAccessUtils.uniqueResult(col)) .satisfies(sizeRequirements(1, 2)); } diff --git a/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java b/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java index 2fa787fd1b..dde5bd1dbf 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java @@ -32,6 +32,7 @@ import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.testfixture.io.SerializationTestUtils; +import org.springframework.transaction.TransactionManager; import org.springframework.transaction.interceptor.NoRollbackRuleAttribute; import org.springframework.transaction.interceptor.RollbackRuleAttribute; import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute; @@ -54,7 +55,7 @@ public class AnnotationTransactionAttributeSourceTests { TestBean1 tb = new TestBean1(); CallCountingTransactionManager ptm = new CallCountingTransactionManager(); AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource(); - TransactionInterceptor ti = new TransactionInterceptor(ptm, tas); + TransactionInterceptor ti = new TransactionInterceptor((TransactionManager) ptm, tas); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setInterfaces(ITestBean1.class); diff --git a/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionInterceptorTests.java b/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionInterceptorTests.java index e026e4ad92..547b79425e 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionInterceptorTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -25,6 +25,7 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import org.springframework.aop.framework.ProxyFactory; +import org.springframework.transaction.TransactionManager; import org.springframework.transaction.interceptor.TransactionInterceptor; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.transaction.testfixture.CallCountingTransactionManager; @@ -48,7 +49,7 @@ public class AnnotationTransactionInterceptorTests { private final AnnotationTransactionAttributeSource source = new AnnotationTransactionAttributeSource(); - private final TransactionInterceptor ti = new TransactionInterceptor(this.ptm, this.source); + private final TransactionInterceptor ti = new TransactionInterceptor((TransactionManager) this.ptm, this.source); @Test diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java b/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java index 779c88c850..f5fe843be7 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java @@ -267,6 +267,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure * if configured by the application, to the given codec , including any * codec it contains. */ + @SuppressWarnings("rawtypes") private void initCodec(@Nullable Object codec) { if (codec instanceof DecoderHttpMessageReader) { diff --git a/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java index fb7abfeb8e..502a75663a 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java @@ -181,16 +181,6 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter { return builder.toString(); } - private boolean compareETagHeaderValue(String requestETag, String responseETag) { - if (requestETag.startsWith("W/")) { - requestETag = requestETag.substring(2); - } - if (responseETag.startsWith("W/")) { - responseETag = responseETag.substring(2); - } - return requestETag.equals(responseETag); - } - /** * This method can be used to suppress the content caching response wrapper diff --git a/spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java b/spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java index c634927807..f320e6675d 100644 --- a/spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java +++ b/spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -32,13 +32,14 @@ import static org.springframework.http.ContentDisposition.builder; * @author Sebastien Deleuze * @author Rossen Stoyanchev */ -public class ContentDispositionTests { +class ContentDispositionTests { private static DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME; @Test - public void parse() { + @SuppressWarnings("deprecation") + void parse() { assertThat(parse("form-data; name=\"foo\"; filename=\"foo.txt\"; size=123")) .isEqualTo(builder("form-data") .name("foo") @@ -48,7 +49,7 @@ public class ContentDispositionTests { } @Test - public void parseFilenameUnquoted() { + void parseFilenameUnquoted() { assertThat(parse("form-data; filename=unquoted")) .isEqualTo(builder("form-data") .filename("unquoted") @@ -56,7 +57,7 @@ public class ContentDispositionTests { } @Test // SPR-16091 - public void parseFilenameWithSemicolon() { + void parseFilenameWithSemicolon() { assertThat(parse("attachment; filename=\"filename with ; semicolon.txt\"")) .isEqualTo(builder("attachment") .filename("filename with ; semicolon.txt") @@ -64,7 +65,7 @@ public class ContentDispositionTests { } @Test - public void parseEncodedFilename() { + void parseEncodedFilename() { assertThat(parse("form-data; name=\"name\"; filename*=UTF-8''%E4%B8%AD%E6%96%87.txt")) .isEqualTo(builder("form-data") .name("name") @@ -73,7 +74,7 @@ public class ContentDispositionTests { } @Test // gh-24112 - public void parseEncodedFilenameWithPaddedCharset() { + void parseEncodedFilenameWithPaddedCharset() { assertThat(parse("attachment; filename*= UTF-8''some-file.zip")) .isEqualTo(builder("attachment") .filename("some-file.zip", StandardCharsets.UTF_8) @@ -81,7 +82,7 @@ public class ContentDispositionTests { } @Test - public void parseEncodedFilenameWithoutCharset() { + void parseEncodedFilenameWithoutCharset() { assertThat(parse("form-data; name=\"name\"; filename*=test.txt")) .isEqualTo(builder("form-data") .name("name") @@ -90,13 +91,13 @@ public class ContentDispositionTests { } @Test - public void parseEncodedFilenameWithInvalidCharset() { + void parseEncodedFilenameWithInvalidCharset() { assertThatIllegalArgumentException() .isThrownBy(() -> parse("form-data; name=\"name\"; filename*=UTF-16''test.txt")); } @Test - public void parseEncodedFilenameWithInvalidName() { + void parseEncodedFilenameWithInvalidName() { assertThatIllegalArgumentException() .isThrownBy(() -> parse("form-data; name=\"name\"; filename*=UTF-8''%A")); @@ -105,8 +106,8 @@ public class ContentDispositionTests { } @Test // gh-23077 - public void parseWithEscapedQuote() { - + @SuppressWarnings("deprecation") + void parseWithEscapedQuote() { BiConsumer tester = (description, filename) -> assertThat(parse("form-data; name=\"file\"; filename=\"" + filename + "\"; size=123")) .as(description) @@ -126,7 +127,8 @@ public class ContentDispositionTests { } @Test - public void parseWithExtraSemicolons() { + @SuppressWarnings("deprecation") + void parseWithExtraSemicolons() { assertThat(parse("form-data; name=\"foo\";; ; filename=\"foo.txt\"; size=123")) .isEqualTo(builder("form-data") .name("foo") @@ -136,7 +138,8 @@ public class ContentDispositionTests { } @Test - public void parseDates() { + @SuppressWarnings("deprecation") + void parseDates() { ZonedDateTime creationTime = ZonedDateTime.parse("Mon, 12 Feb 2007 10:15:30 -0500", formatter); ZonedDateTime modificationTime = ZonedDateTime.parse("Tue, 13 Feb 2007 10:15:30 -0500", formatter); ZonedDateTime readTime = ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter); @@ -154,7 +157,8 @@ public class ContentDispositionTests { } @Test - public void parseIgnoresInvalidDates() { + @SuppressWarnings("deprecation") + void parseIgnoresInvalidDates() { ZonedDateTime readTime = ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter); assertThat( @@ -168,17 +172,17 @@ public class ContentDispositionTests { } @Test - public void parseEmpty() { + void parseEmpty() { assertThatIllegalArgumentException().isThrownBy(() -> parse("")); } @Test - public void parseNoType() { + void parseNoType() { assertThatIllegalArgumentException().isThrownBy(() -> parse(";")); } @Test - public void parseInvalidParameter() { + void parseInvalidParameter() { assertThatIllegalArgumentException().isThrownBy(() -> parse("foo;bar")); } @@ -188,7 +192,8 @@ public class ContentDispositionTests { @Test - public void format() { + @SuppressWarnings("deprecation") + void format() { assertThat( builder("form-data") .name("foo") @@ -199,7 +204,7 @@ public class ContentDispositionTests { } @Test - public void formatWithEncodedFilename() { + void formatWithEncodedFilename() { assertThat( builder("form-data") .name("name") @@ -209,7 +214,7 @@ public class ContentDispositionTests { } @Test - public void formatWithEncodedFilenameUsingUsAscii() { + void formatWithEncodedFilenameUsingUsAscii() { assertThat( builder("form-data") .name("name") @@ -220,7 +225,7 @@ public class ContentDispositionTests { } @Test // gh-24220 - public void formatWithFilenameWithQuotes() { + void formatWithFilenameWithQuotes() { BiConsumer tester = (input, output) -> { @@ -255,7 +260,7 @@ public class ContentDispositionTests { } @Test - public void formatWithEncodedFilenameUsingInvalidCharset() { + void formatWithEncodedFilenameUsingInvalidCharset() { assertThatIllegalArgumentException().isThrownBy(() -> builder("form-data") .name("name") diff --git a/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java b/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java index f9bebd095a..a36415ff00 100644 --- a/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java +++ b/spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -59,7 +59,7 @@ public class HttpHeadersTests { @Test - public void getOrEmpty() { + void getOrEmpty() { String key = "FOO"; assertThat(headers.get(key)).isNull(); @@ -74,14 +74,14 @@ public class HttpHeadersTests { } @Test - public void getFirst() { + void getFirst() { headers.add(HttpHeaders.CACHE_CONTROL, "max-age=1000, public"); headers.add(HttpHeaders.CACHE_CONTROL, "s-maxage=1000"); assertThat(headers.getFirst(HttpHeaders.CACHE_CONTROL)).isEqualTo("max-age=1000, public"); } @Test - public void accept() { + void accept() { MediaType mediaType1 = new MediaType("text", "html"); MediaType mediaType2 = new MediaType("text", "plain"); List mediaTypes = new ArrayList<>(2); @@ -93,7 +93,7 @@ public class HttpHeadersTests { } @Test // SPR-9655 - public void acceptWithMultipleHeaderValues() { + void acceptWithMultipleHeaderValues() { headers.add("Accept", "text/html"); headers.add("Accept", "text/plain"); List expected = Arrays.asList(new MediaType("text", "html"), new MediaType("text", "plain")); @@ -101,7 +101,7 @@ public class HttpHeadersTests { } @Test // SPR-14506 - public void acceptWithMultipleCommaSeparatedHeaderValues() { + void acceptWithMultipleCommaSeparatedHeaderValues() { headers.add("Accept", "text/html,text/pdf"); headers.add("Accept", "text/plain,text/csv"); List expected = Arrays.asList(new MediaType("text", "html"), new MediaType("text", "pdf"), @@ -110,7 +110,7 @@ public class HttpHeadersTests { } @Test - public void acceptCharsets() { + void acceptCharsets() { Charset charset1 = StandardCharsets.UTF_8; Charset charset2 = StandardCharsets.ISO_8859_1; List charsets = new ArrayList<>(2); @@ -122,13 +122,13 @@ public class HttpHeadersTests { } @Test - public void acceptCharsetWildcard() { + void acceptCharsetWildcard() { headers.set("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); assertThat(headers.getAcceptCharset()).as("Invalid Accept header").isEqualTo(Arrays.asList(StandardCharsets.ISO_8859_1, StandardCharsets.UTF_8)); } @Test - public void allow() { + void allow() { EnumSet methods = EnumSet.of(HttpMethod.GET, HttpMethod.POST); headers.setAllow(methods); assertThat(headers.getAllow()).as("Invalid Allow header").isEqualTo(methods); @@ -136,7 +136,7 @@ public class HttpHeadersTests { } @Test - public void contentLength() { + void contentLength() { long length = 42L; headers.setContentLength(length); assertThat(headers.getContentLength()).as("Invalid Content-Length header").isEqualTo(length); @@ -144,7 +144,7 @@ public class HttpHeadersTests { } @Test - public void contentType() { + void contentType() { MediaType contentType = new MediaType("text", "html", StandardCharsets.UTF_8); headers.setContentType(contentType); assertThat(headers.getContentType()).as("Invalid Content-Type header").isEqualTo(contentType); @@ -152,7 +152,7 @@ public class HttpHeadersTests { } @Test - public void location() throws URISyntaxException { + void location() throws URISyntaxException { URI location = new URI("https://www.example.com/hotels"); headers.setLocation(location); assertThat(headers.getLocation()).as("Invalid Location header").isEqualTo(location); @@ -160,7 +160,7 @@ public class HttpHeadersTests { } @Test - public void eTag() { + void eTag() { String eTag = "\"v2.6\""; headers.setETag(eTag); assertThat(headers.getETag()).as("Invalid ETag header").isEqualTo(eTag); @@ -168,7 +168,7 @@ public class HttpHeadersTests { } @Test - public void host() { + void host() { InetSocketAddress host = InetSocketAddress.createUnresolved("localhost", 8080); headers.setHost(host); assertThat(headers.getHost()).as("Invalid Host header").isEqualTo(host); @@ -176,7 +176,7 @@ public class HttpHeadersTests { } @Test - public void hostNoPort() { + void hostNoPort() { InetSocketAddress host = InetSocketAddress.createUnresolved("localhost", 0); headers.setHost(host); assertThat(headers.getHost()).as("Invalid Host header").isEqualTo(host); @@ -184,7 +184,7 @@ public class HttpHeadersTests { } @Test - public void ipv6Host() { + void ipv6Host() { InetSocketAddress host = InetSocketAddress.createUnresolved("[::1]", 0); headers.setHost(host); assertThat(headers.getHost()).as("Invalid Host header").isEqualTo(host); @@ -192,13 +192,13 @@ public class HttpHeadersTests { } @Test - public void illegalETag() { + void illegalETag() { String eTag = "v2.6"; assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(eTag)); } @Test - public void ifMatch() { + void ifMatch() { String ifMatch = "\"v2.6\""; headers.setIfMatch(ifMatch); assertThat(headers.getIfMatch().get(0)).as("Invalid If-Match header").isEqualTo(ifMatch); @@ -206,13 +206,13 @@ public class HttpHeadersTests { } @Test - public void ifMatchIllegalHeader() { + void ifMatchIllegalHeader() { headers.setIfMatch("Illegal"); assertThatIllegalArgumentException().isThrownBy(headers::getIfMatch); } @Test - public void ifMatchMultipleHeaders() { + void ifMatchMultipleHeaders() { headers.add(HttpHeaders.IF_MATCH, "\"v2,0\""); headers.add(HttpHeaders.IF_MATCH, "W/\"v2,1\", \"v2,2\""); assertThat(headers.get(HttpHeaders.IF_MATCH).get(0)).as("Invalid If-Match header").isEqualTo("\"v2,0\""); @@ -221,7 +221,7 @@ public class HttpHeadersTests { } @Test - public void ifNoneMatch() { + void ifNoneMatch() { String ifNoneMatch = "\"v2.6\""; headers.setIfNoneMatch(ifNoneMatch); assertThat(headers.getIfNoneMatch().get(0)).as("Invalid If-None-Match header").isEqualTo(ifNoneMatch); @@ -229,7 +229,7 @@ public class HttpHeadersTests { } @Test - public void ifNoneMatchWildCard() { + void ifNoneMatchWildCard() { String ifNoneMatch = "*"; headers.setIfNoneMatch(ifNoneMatch); assertThat(headers.getIfNoneMatch().get(0)).as("Invalid If-None-Match header").isEqualTo(ifNoneMatch); @@ -237,7 +237,7 @@ public class HttpHeadersTests { } @Test - public void ifNoneMatchList() { + void ifNoneMatchList() { String ifNoneMatch1 = "\"v2.6\""; String ifNoneMatch2 = "\"v2.7\", \"v2.8\""; List ifNoneMatchList = new ArrayList<>(2); @@ -249,7 +249,7 @@ public class HttpHeadersTests { } @Test - public void date() { + void date() { Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20); calendar.setTimeZone(TimeZone.getTimeZone("CET")); long date = calendar.getTimeInMillis(); @@ -263,13 +263,13 @@ public class HttpHeadersTests { } @Test - public void dateInvalid() { + void dateInvalid() { headers.set("Date", "Foo Bar Baz"); assertThatIllegalArgumentException().isThrownBy(headers::getDate); } @Test - public void dateOtherLocale() { + void dateOtherLocale() { Locale defaultLocale = Locale.getDefault(); try { Locale.setDefault(new Locale("nl", "nl")); @@ -286,7 +286,7 @@ public class HttpHeadersTests { } @Test - public void lastModified() { + void lastModified() { Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20); calendar.setTimeZone(TimeZone.getTimeZone("CET")); long date = calendar.getTimeInMillis(); @@ -296,7 +296,7 @@ public class HttpHeadersTests { } @Test - public void expiresLong() { + void expiresLong() { Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20); calendar.setTimeZone(TimeZone.getTimeZone("CET")); long date = calendar.getTimeInMillis(); @@ -306,7 +306,7 @@ public class HttpHeadersTests { } @Test - public void expiresZonedDateTime() { + void expiresZonedDateTime() { ZonedDateTime zonedDateTime = ZonedDateTime.of(2008, 12, 18, 10, 20, 0, 0, ZoneId.of("GMT")); headers.setExpires(zonedDateTime); assertThat(headers.getExpires()).as("Invalid Expires header").isEqualTo(zonedDateTime.toInstant().toEpochMilli()); @@ -314,13 +314,13 @@ public class HttpHeadersTests { } @Test // SPR-10648 (example is from INT-3063) - public void expiresInvalidDate() { + void expiresInvalidDate() { headers.set("Expires", "-1"); assertThat(headers.getExpires()).isEqualTo(-1); } @Test - public void ifModifiedSince() { + void ifModifiedSince() { Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20); calendar.setTimeZone(TimeZone.getTimeZone("CET")); long date = calendar.getTimeInMillis(); @@ -330,7 +330,7 @@ public class HttpHeadersTests { } @Test // SPR-14144 - public void invalidIfModifiedSinceHeader() { + void invalidIfModifiedSinceHeader() { headers.set(HttpHeaders.IF_MODIFIED_SINCE, "0"); assertThat(headers.getIfModifiedSince()).isEqualTo(-1); @@ -342,7 +342,7 @@ public class HttpHeadersTests { } @Test - public void pragma() { + void pragma() { String pragma = "no-cache"; headers.setPragma(pragma); assertThat(headers.getPragma()).as("Invalid Pragma header").isEqualTo(pragma); @@ -350,35 +350,36 @@ public class HttpHeadersTests { } @Test - public void cacheControl() { + void cacheControl() { headers.setCacheControl("no-cache"); assertThat(headers.getCacheControl()).as("Invalid Cache-Control header").isEqualTo("no-cache"); assertThat(headers.getFirst("cache-control")).as("Invalid Cache-Control header").isEqualTo("no-cache"); } @Test - public void cacheControlBuilder() { + void cacheControlBuilder() { headers.setCacheControl(CacheControl.noCache()); assertThat(headers.getCacheControl()).as("Invalid Cache-Control header").isEqualTo("no-cache"); assertThat(headers.getFirst("cache-control")).as("Invalid Cache-Control header").isEqualTo("no-cache"); } @Test - public void cacheControlEmpty() { + void cacheControlEmpty() { headers.setCacheControl(CacheControl.empty()); assertThat(headers.getCacheControl()).as("Invalid Cache-Control header").isNull(); assertThat(headers.getFirst("cache-control")).as("Invalid Cache-Control header").isNull(); } @Test - public void cacheControlAllValues() { + void cacheControlAllValues() { headers.add(HttpHeaders.CACHE_CONTROL, "max-age=1000, public"); headers.add(HttpHeaders.CACHE_CONTROL, "s-maxage=1000"); assertThat(headers.getCacheControl()).isEqualTo("max-age=1000, public, s-maxage=1000"); } @Test - public void contentDisposition() { + @SuppressWarnings("deprecation") + void contentDisposition() { ContentDisposition disposition = headers.getContentDisposition(); assertThat(disposition).isNotNull(); assertThat(headers.getContentDisposition()).as("Invalid Content-Disposition header").isEqualTo(ContentDisposition.empty()); @@ -389,13 +390,13 @@ public class HttpHeadersTests { } @Test // SPR-11917 - public void getAllowEmptySet() { + void getAllowEmptySet() { headers.setAllow(Collections.emptySet()); assertThat(headers.getAllow()).isEmpty(); } @Test - public void accessControlAllowCredentials() { + void accessControlAllowCredentials() { assertThat(headers.getAccessControlAllowCredentials()).isFalse(); headers.setAccessControlAllowCredentials(false); assertThat(headers.getAccessControlAllowCredentials()).isFalse(); @@ -404,7 +405,7 @@ public class HttpHeadersTests { } @Test - public void accessControlAllowHeaders() { + void accessControlAllowHeaders() { List allowedHeaders = headers.getAccessControlAllowHeaders(); assertThat(allowedHeaders).isEmpty(); headers.setAccessControlAllowHeaders(Arrays.asList("header1", "header2")); @@ -413,7 +414,7 @@ public class HttpHeadersTests { } @Test - public void accessControlAllowHeadersMultipleValues() { + void accessControlAllowHeadersMultipleValues() { List allowedHeaders = headers.getAccessControlAllowHeaders(); assertThat(allowedHeaders).isEmpty(); headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "header1, header2"); @@ -423,7 +424,7 @@ public class HttpHeadersTests { } @Test - public void accessControlAllowMethods() { + void accessControlAllowMethods() { List allowedMethods = headers.getAccessControlAllowMethods(); assertThat(allowedMethods).isEmpty(); headers.setAccessControlAllowMethods(Arrays.asList(HttpMethod.GET, HttpMethod.POST)); @@ -432,14 +433,14 @@ public class HttpHeadersTests { } @Test - public void accessControlAllowOrigin() { + void accessControlAllowOrigin() { assertThat(headers.getAccessControlAllowOrigin()).isNull(); headers.setAccessControlAllowOrigin("*"); assertThat(headers.getAccessControlAllowOrigin()).isEqualTo("*"); } @Test - public void accessControlExposeHeaders() { + void accessControlExposeHeaders() { List exposedHeaders = headers.getAccessControlExposeHeaders(); assertThat(exposedHeaders).isEmpty(); headers.setAccessControlExposeHeaders(Arrays.asList("header1", "header2")); @@ -448,14 +449,14 @@ public class HttpHeadersTests { } @Test - public void accessControlMaxAge() { + void accessControlMaxAge() { assertThat(headers.getAccessControlMaxAge()).isEqualTo(-1); headers.setAccessControlMaxAge(3600); assertThat(headers.getAccessControlMaxAge()).isEqualTo(3600); } @Test - public void accessControlRequestHeaders() { + void accessControlRequestHeaders() { List requestHeaders = headers.getAccessControlRequestHeaders(); assertThat(requestHeaders).isEmpty(); headers.setAccessControlRequestHeaders(Arrays.asList("header1", "header2")); @@ -464,14 +465,14 @@ public class HttpHeadersTests { } @Test - public void accessControlRequestMethod() { + void accessControlRequestMethod() { assertThat(headers.getAccessControlRequestMethod()).isNull(); headers.setAccessControlRequestMethod(HttpMethod.POST); assertThat(headers.getAccessControlRequestMethod()).isEqualTo(HttpMethod.POST); } @Test - public void acceptLanguage() { + void acceptLanguage() { String headerValue = "fr-ch, fr;q=0.9, en-*;q=0.8, de;q=0.7, *;q=0.5"; headers.setAcceptLanguage(Locale.LanguageRange.parse(headerValue)); assertThat(headers.getFirst(HttpHeaders.ACCEPT_LANGUAGE)).isEqualTo(headerValue); @@ -491,26 +492,26 @@ public class HttpHeadersTests { } @Test // SPR-15603 - public void acceptLanguageWithEmptyValue() throws Exception { + void acceptLanguageWithEmptyValue() throws Exception { this.headers.set(HttpHeaders.ACCEPT_LANGUAGE, ""); assertThat(this.headers.getAcceptLanguageAsLocales()).isEqualTo(Collections.emptyList()); } @Test - public void contentLanguage() { + void contentLanguage() { headers.setContentLanguage(Locale.FRANCE); assertThat(headers.getContentLanguage()).isEqualTo(Locale.FRANCE); assertThat(headers.getFirst(HttpHeaders.CONTENT_LANGUAGE)).isEqualTo("fr-FR"); } @Test - public void contentLanguageSerialized() { + void contentLanguageSerialized() { headers.set(HttpHeaders.CONTENT_LANGUAGE, "de, en_CA"); assertThat(headers.getContentLanguage()).as("Expected one (first) locale").isEqualTo(Locale.GERMAN); } @Test - public void firstDate() { + void firstDate() { headers.setDate(HttpHeaders.DATE, 1496370120000L); assertThat(headers.getFirstDate(HttpHeaders.DATE)).isEqualTo(1496370120000L); @@ -522,7 +523,7 @@ public class HttpHeadersTests { } @Test - public void firstZonedDateTime() { + void firstZonedDateTime() { ZonedDateTime date = ZonedDateTime.of(2017, 6, 2, 2, 22, 0, 0, ZoneId.of("GMT")); headers.setZonedDateTime(HttpHeaders.DATE, date); assertThat(headers.getFirst(HttpHeaders.DATE)).isEqualTo("Fri, 02 Jun 2017 02:22:00 GMT"); @@ -547,7 +548,7 @@ public class HttpHeadersTests { } @Test - public void basicAuth() { + void basicAuth() { String username = "foo"; String password = "bar"; headers.setBasicAuth(username, password); @@ -559,14 +560,14 @@ public class HttpHeadersTests { } @Test - public void basicAuthIllegalChar() { + void basicAuthIllegalChar() { String username = "foo"; String password = "\u03BB"; assertThatIllegalArgumentException().isThrownBy(() -> headers.setBasicAuth(username, password)); } @Test - public void bearerAuth() { + void bearerAuth() { String token = "foo"; headers.setBearerAuth(token); @@ -575,7 +576,7 @@ public class HttpHeadersTests { } @Test - public void keySetOperations() { + void keySetOperations() { headers.add("Alpha", "apple"); headers.add("Bravo", "banana"); Set keySet = headers.keySet(); @@ -634,7 +635,7 @@ public class HttpHeadersTests { * than {@link #removalFromKeySetRemovesEntryFromUnderlyingMap()}. */ @Test // https://github.com/spring-projects/spring-framework/issues/23633 - public void keySetRemovalChecks() { + void keySetRemovalChecks() { // --- Given --- headers.add("Alpha", "apple"); headers.add("Bravo", "banana"); @@ -660,7 +661,7 @@ public class HttpHeadersTests { } @Test - public void removalFromKeySetRemovesEntryFromUnderlyingMap() { + void removalFromKeySetRemovesEntryFromUnderlyingMap() { String headerName = "MyHeader"; String headerValue = "value"; @@ -674,7 +675,7 @@ public class HttpHeadersTests { } @Test - public void removalFromEntrySetRemovesEntryFromUnderlyingMap() { + void removalFromEntrySetRemovesEntryFromUnderlyingMap() { String headerName = "MyHeader"; String headerValue = "value"; @@ -688,7 +689,7 @@ public class HttpHeadersTests { } @Test - public void readOnlyHttpHeadersRetainEntrySetOrder() { + void readOnlyHttpHeadersRetainEntrySetOrder() { headers.add("aardvark", "enigma"); headers.add("beaver", "enigma"); headers.add("cat", "enigma"); @@ -704,11 +705,12 @@ public class HttpHeadersTests { } @Test // gh-25034 - public void equalsUnwrapsHttpHeaders() { + void equalsUnwrapsHttpHeaders() { HttpHeaders headers1 = new HttpHeaders(); HttpHeaders headers2 = new HttpHeaders(new HttpHeaders(headers1)); assertThat(headers1).isEqualTo(headers2); assertThat(headers2).isEqualTo(headers1); } + } diff --git a/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java b/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java index 9790b1a11e..e165ef8082 100644 --- a/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java +++ b/spring-web/src/test/java/org/springframework/http/RequestEntityTests.java @@ -27,7 +27,6 @@ import java.util.Map; import org.junit.jupiter.api.Test; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.web.util.DefaultUriBuilderFactory; import org.springframework.web.util.UriComponentsBuilder; import static org.assertj.core.api.Assertions.assertThat; @@ -38,10 +37,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Arjen Poutsma * @author Parviz Rozikov */ -public class RequestEntityTests { +class RequestEntityTests { @Test - public void normal() throws URISyntaxException { + void normal() throws URISyntaxException { String headerName = "My-Custom-Header"; String headerValue = "HeaderValue"; URI url = new URI("https://example.com"); @@ -59,7 +58,7 @@ public class RequestEntityTests { } @Test - public void uriVariablesExpansion() throws URISyntaxException { + void uriVariablesExpansion() throws URISyntaxException { URI uri = UriComponentsBuilder.fromUriString("https://example.com/{foo}").buildAndExpand("bar").toUri(); RequestEntity.get(uri).accept(MediaType.TEXT_PLAIN).build(); @@ -82,22 +81,20 @@ public class RequestEntityTests { } @Test - public void uriExpansion() { - + void uriExpansion() { RequestEntity entity = RequestEntity.get("https://www.{host}.com/{path}", "example", "foo/bar").build(); assertThat(entity).isInstanceOf(RequestEntity.UriTemplateRequestEntity.class); RequestEntity.UriTemplateRequestEntity ext = (RequestEntity.UriTemplateRequestEntity) entity; - DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); assertThat(ext.getUriTemplate()).isEqualTo("https://www.{host}.com/{path}"); assertThat(ext.getVars()).containsExactly("example", "foo/bar"); } @Test - public void get() { + void get() { RequestEntity requestEntity = RequestEntity.get(URI.create("https://example.com")).accept( MediaType.IMAGE_GIF, MediaType.IMAGE_JPEG, MediaType.IMAGE_PNG).build(); @@ -109,7 +106,7 @@ public class RequestEntityTests { } @Test - public void headers() throws URISyntaxException { + void headers() throws URISyntaxException { MediaType accept = MediaType.TEXT_PLAIN; long ifModifiedSince = 12345L; String ifNoneMatch = "\"foo\""; @@ -142,7 +139,7 @@ public class RequestEntityTests { } @Test - public void methods() throws URISyntaxException { + void methods() throws URISyntaxException { URI url = new URI("https://example.com"); RequestEntity entity = RequestEntity.get(url).build(); @@ -169,7 +166,7 @@ public class RequestEntityTests { } @Test // SPR-13154 - public void types() throws URISyntaxException { + void types() throws URISyntaxException { URI url = new URI("https://example.com"); List body = Arrays.asList("foo", "bar"); ParameterizedTypeReference typeReference = new ParameterizedTypeReference>() {}; diff --git a/spring-web/src/test/java/org/springframework/http/client/AbstractAsyncHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/AbstractAsyncHttpRequestFactoryTests.java index c9e8789297..4ae702d551 100644 --- a/spring-web/src/test/java/org/springframework/http/client/AbstractAsyncHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/AbstractAsyncHttpRequestFactoryTests.java @@ -134,7 +134,6 @@ public abstract class AbstractAsyncHttpRequestFactoryTests extends AbstractMockW } @Test - @SuppressWarnings("try") public void multipleWrites() throws Exception { AsyncClientHttpRequest request = this.factory.createAsyncRequest(new URI(baseUrl + "/echo"), HttpMethod.POST); final byte[] body = "Hello World".getBytes("UTF-8"); @@ -149,12 +148,12 @@ public abstract class AbstractAsyncHttpRequestFactoryTests extends AbstractMockW Future futureResponse = request.executeAsync(); try (ClientHttpResponse response = futureResponse.get()) { + assertThat(response).isNotNull(); assertThatIllegalStateException().isThrownBy(() -> FileCopyUtils.copy(body, request.getBody())); } } @Test - @SuppressWarnings("try") public void headersAfterExecute() throws Exception { AsyncClientHttpRequest request = this.factory.createAsyncRequest(new URI(baseUrl + "/echo"), HttpMethod.POST); request.getHeaders().add("MyHeader", "value"); @@ -163,6 +162,7 @@ public abstract class AbstractAsyncHttpRequestFactoryTests extends AbstractMockW Future futureResponse = request.executeAsync(); try (ClientHttpResponse response = futureResponse.get()) { + assertThat(response).isNotNull(); assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> request.getHeaders().add("MyHeader", "value")); } 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 58a0a9cc69..f231495ddf 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 @@ -129,7 +129,6 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest } @Test - @SuppressWarnings("try") void headersAfterExecute() throws Exception { ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/status/ok"), HttpMethod.POST); @@ -138,6 +137,7 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> { FileCopyUtils.copy(body, request.getBody()); try (ClientHttpResponse response = request.execute()) { + assertThat(response).isNotNull(); request.getHeaders().add("MyHeader", "value"); } }); diff --git a/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java index 39e831b5fc..162c8ecfa5 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/EncoderHttpMessageWriterTests.java @@ -210,11 +210,4 @@ class EncoderHttpMessageWriterTests { .willReturn(encodedStream); } - private void configureEncoder(DataBuffer dataBuffer, MimeType... mimeTypes) { - List typeList = Arrays.asList(mimeTypes); - given(this.encoder.getEncodableMimeTypes()).willReturn(typeList); - given(this.encoder.encodeValue(any(), any(), any(), this.mediaTypeCaptor.capture(), any())) - .willReturn(dataBuffer); - } - } diff --git a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java index 2c0169c997..ec85f08c99 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java @@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * * @author Rossen Stoyanchev */ -public class ContentNegotiationManagerFactoryBeanTests { +class ContentNegotiationManagerFactoryBeanTests { private ContentNegotiationManagerFactoryBean factoryBean; @@ -52,7 +52,7 @@ public class ContentNegotiationManagerFactoryBeanTests { @BeforeEach - public void setup() { + void setup() { TestServletContext servletContext = new TestServletContext(); servletContext.getMimeTypes().put("foo", "application/foo"); @@ -65,7 +65,7 @@ public class ContentNegotiationManagerFactoryBeanTests { @Test - public void defaultSettings() throws Exception { + void defaultSettings() throws Exception { this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); @@ -97,7 +97,7 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test - public void explicitStrategies() throws Exception { + void explicitStrategies() throws Exception { Map mediaTypes = Collections.singletonMap("bar", new MediaType("application", "bar")); ParameterContentNegotiationStrategy strategy1 = new ParameterContentNegotiationStrategy(mediaTypes); HeaderContentNegotiationStrategy strategy2 = new HeaderContentNegotiationStrategy(); @@ -116,7 +116,8 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test - public void favorPath() throws Exception { + @SuppressWarnings("deprecation") + void favorPath() throws Exception { this.factoryBean.setFavorPathExtension(true); this.factoryBean.addMediaType("bar", new MediaType("application", "bar")); this.factoryBean.afterPropertiesSet(); @@ -136,7 +137,8 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test // SPR-10170 - public void favorPathWithIgnoreUnknownPathExtensionTurnedOff() { + @SuppressWarnings("deprecation") + void favorPathWithIgnoreUnknownPathExtensionTurnedOff() { this.factoryBean.setFavorPathExtension(true); this.factoryBean.setIgnoreUnknownPathExtensions(false); this.factoryBean.afterPropertiesSet(); @@ -150,7 +152,7 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test - public void favorParameter() throws Exception { + void favorParameter() throws Exception { this.factoryBean.setFavorParameter(true); this.factoryBean.addMediaType("json", MediaType.APPLICATION_JSON); @@ -165,7 +167,7 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test // SPR-10170 - public void favorParameterWithUnknownMediaType() { + void favorParameterWithUnknownMediaType() { this.factoryBean.setFavorParameter(true); this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); @@ -178,8 +180,8 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test - public void mediaTypeMappingsWithoutPathAndParameterStrategies() { - + @SuppressWarnings("deprecation") + void mediaTypeMappingsWithoutPathAndParameterStrategies() { this.factoryBean.setFavorPathExtension(false); this.factoryBean.setFavorParameter(false); @@ -199,8 +201,8 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test - public void fileExtensions() { - + @SuppressWarnings("deprecation") + void fileExtensions() { this.factoryBean.setFavorPathExtension(false); this.factoryBean.setFavorParameter(false); @@ -222,7 +224,7 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test - public void ignoreAcceptHeader() throws Exception { + void ignoreAcceptHeader() throws Exception { this.factoryBean.setIgnoreAcceptHeader(true); this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); @@ -235,7 +237,7 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test - public void setDefaultContentType() throws Exception { + void setDefaultContentType() throws Exception { this.factoryBean.setDefaultContentType(MediaType.APPLICATION_JSON); this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); @@ -248,7 +250,7 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test // SPR-15367 - public void setDefaultContentTypes() throws Exception { + void setDefaultContentTypes() throws Exception { List mediaTypes = Arrays.asList(MediaType.APPLICATION_JSON, MediaType.ALL); this.factoryBean.setDefaultContentTypes(mediaTypes); this.factoryBean.afterPropertiesSet(); @@ -261,7 +263,7 @@ public class ContentNegotiationManagerFactoryBeanTests { } @Test // SPR-12286 - public void setDefaultContentTypeWithStrategy() throws Exception { + void setDefaultContentTypeWithStrategy() throws Exception { this.factoryBean.setDefaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON)); this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); diff --git a/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java b/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java index 5f394907da..3dfd0e8ec2 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.accept; import java.util.Arrays; @@ -20,7 +21,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; @@ -33,103 +33,79 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** - * A test fixture for PathExtensionContentNegotiationStrategy. + * A test fixture for {@link PathExtensionContentNegotiationStrategy}. * * @author Rossen Stoyanchev * @since 3.2 */ -public class PathExtensionContentNegotiationStrategyTests { +@SuppressWarnings("deprecation") +class PathExtensionContentNegotiationStrategyTests { - private NativeWebRequest webRequest; + private final MockHttpServletRequest servletRequest = new MockHttpServletRequest(); - private MockHttpServletRequest servletRequest; + private final NativeWebRequest webRequest = new ServletWebRequest(servletRequest); - - @BeforeEach - public void setup() { - this.servletRequest = new MockHttpServletRequest(); - this.webRequest = new ServletWebRequest(servletRequest); - } + private PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(); @Test - public void resolveMediaTypesFromMapping() throws Exception { - + void resolveMediaTypesFromMapping() throws Exception { this.servletRequest.setRequestURI("test.html"); - PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(); - List mediaTypes = strategy.resolveMediaTypes(this.webRequest); + List mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); assertThat(mediaTypes).isEqualTo(Arrays.asList(new MediaType("text", "html"))); Map mapping = Collections.singletonMap("HTML", MediaType.APPLICATION_XHTML_XML); - strategy = new PathExtensionContentNegotiationStrategy(mapping); - mediaTypes = strategy.resolveMediaTypes(this.webRequest); + this.strategy = new PathExtensionContentNegotiationStrategy(mapping); + mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); assertThat(mediaTypes).isEqualTo(Arrays.asList(new MediaType("application", "xhtml+xml"))); } @Test - public void resolveMediaTypesFromMediaTypeFactory() throws Exception { - + void resolveMediaTypesFromMediaTypeFactory() throws Exception { this.servletRequest.setRequestURI("test.xls"); - PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(); - List mediaTypes = strategy.resolveMediaTypes(this.webRequest); + List mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); assertThat(mediaTypes).isEqualTo(Arrays.asList(new MediaType("application", "vnd.ms-excel"))); } - // SPR-8678 - - @Test - public void getMediaTypeFilenameWithContextPath() throws Exception { - - PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(); - + @Test // SPR-8678 + void getMediaTypeFilenameWithContextPath() throws Exception { this.servletRequest.setContextPath("/project-1.0.0.M3"); this.servletRequest.setRequestURI("/project-1.0.0.M3/"); - assertThat(strategy.resolveMediaTypes(webRequest)).as("Context path should be excluded").isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST); + assertThat(this.strategy.resolveMediaTypes(webRequest)).as("Context path should be excluded").isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST); this.servletRequest.setRequestURI("/project-1.0.0.M3"); - assertThat(strategy.resolveMediaTypes(webRequest)).as("Context path should be excluded").isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST); + assertThat(this.strategy.resolveMediaTypes(webRequest)).as("Context path should be excluded").isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST); } - // SPR-9390 - - @Test - public void getMediaTypeFilenameWithEncodedURI() throws Exception { - + @Test // SPR-9390 + void getMediaTypeFilenameWithEncodedURI() throws Exception { this.servletRequest.setRequestURI("/quo%20vadis%3f.html"); - - PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(); - List result = strategy.resolveMediaTypes(webRequest); + List result = this.strategy.resolveMediaTypes(webRequest); assertThat(result).as("Invalid content type").isEqualTo(Collections.singletonList(new MediaType("text", "html"))); } - // SPR-10170 - - @Test - public void resolveMediaTypesIgnoreUnknownExtension() throws Exception { - + @Test // SPR-10170 + void resolveMediaTypesIgnoreUnknownExtension() throws Exception { this.servletRequest.setRequestURI("test.foobar"); - PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(); - List mediaTypes = strategy.resolveMediaTypes(this.webRequest); + List mediaTypes = this.strategy.resolveMediaTypes(this.webRequest); assertThat(mediaTypes).isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST); } @Test - public void resolveMediaTypesDoNotIgnoreUnknownExtension() throws Exception { - + void resolveMediaTypesDoNotIgnoreUnknownExtension() { this.servletRequest.setRequestURI("test.foobar"); - PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(); - strategy.setIgnoreUnknownExtensions(false); - assertThatExceptionOfType(HttpMediaTypeNotAcceptableException.class).isThrownBy(() -> - strategy.resolveMediaTypes(this.webRequest)); + this.strategy.setIgnoreUnknownExtensions(false); + assertThatExceptionOfType(HttpMediaTypeNotAcceptableException.class) + .isThrownBy(() -> this.strategy.resolveMediaTypes(this.webRequest)); } } 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 3877572704..2c727e67ad 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -81,36 +81,30 @@ import static org.springframework.http.MediaType.parseMediaType; * @author Sam Brannen */ @SuppressWarnings("unchecked") -public class RestTemplateTests { +class RestTemplateTests { - private RestTemplate template; + private final ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class); - private ClientHttpRequestFactory requestFactory; + private final ClientHttpRequest request = mock(ClientHttpRequest.class); - private ClientHttpRequest request; + private final ClientHttpResponse response = mock(ClientHttpResponse.class); - private ClientHttpResponse response; - - private ResponseErrorHandler errorHandler; + private final ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class); @SuppressWarnings("rawtypes") - private HttpMessageConverter converter; + private final HttpMessageConverter converter = mock(HttpMessageConverter.class); + + private final RestTemplate template = new RestTemplate(Collections.singletonList(converter)); @BeforeEach - public void setup() { - requestFactory = mock(ClientHttpRequestFactory.class); - request = mock(ClientHttpRequest.class); - response = mock(ClientHttpResponse.class); - errorHandler = mock(ResponseErrorHandler.class); - converter = mock(HttpMessageConverter.class); - template = new RestTemplate(Collections.singletonList(converter)); + void setup() { template.setRequestFactory(requestFactory); template.setErrorHandler(errorHandler); } @Test - public void constructorPreconditions() { + void constructorPreconditions() { assertThatIllegalArgumentException() .isThrownBy(() -> new RestTemplate((List>) null)) .withMessage("At least one HttpMessageConverter is required"); @@ -120,7 +114,7 @@ public class RestTemplateTests { } @Test - public void setMessageConvertersPreconditions() { + void setMessageConvertersPreconditions() { assertThatIllegalArgumentException() .isThrownBy(() -> template.setMessageConverters((List>) null)) .withMessage("At least one HttpMessageConverter is required"); @@ -130,7 +124,7 @@ public class RestTemplateTests { } @Test - public void varArgsTemplateVariables() throws Exception { + void varArgsTemplateVariables() throws Exception { mockSentRequest(GET, "https://example.com/hotels/42/bookings/21"); mockResponseStatus(HttpStatus.OK); @@ -141,7 +135,7 @@ public class RestTemplateTests { } @Test - public void varArgsNullTemplateVariable() throws Exception { + void varArgsNullTemplateVariable() throws Exception { mockSentRequest(GET, "https://example.com/-foo"); mockResponseStatus(HttpStatus.OK); @@ -151,7 +145,7 @@ public class RestTemplateTests { } @Test - public void mapTemplateVariables() throws Exception { + void mapTemplateVariables() throws Exception { mockSentRequest(GET, "https://example.com/hotels/42/bookings/42"); mockResponseStatus(HttpStatus.OK); @@ -162,7 +156,7 @@ public class RestTemplateTests { } @Test - public void mapNullTemplateVariable() throws Exception { + void mapNullTemplateVariable() throws Exception { mockSentRequest(GET, "https://example.com/-foo"); mockResponseStatus(HttpStatus.OK); @@ -175,7 +169,7 @@ public class RestTemplateTests { } @Test // SPR-15201 - public void uriTemplateWithTrailingSlash() throws Exception { + void uriTemplateWithTrailingSlash() throws Exception { String url = "https://example.com/spring/"; mockSentRequest(GET, url); mockResponseStatus(HttpStatus.OK); @@ -186,7 +180,7 @@ public class RestTemplateTests { } @Test - public void errorHandling() throws Exception { + void errorHandling() throws Exception { String url = "https://example.com"; mockSentRequest(GET, url); mockResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR); @@ -200,7 +194,7 @@ public class RestTemplateTests { } @Test - public void getForObject() throws Exception { + void getForObject() throws Exception { String expected = "Hello World"; mockTextPlainHttpMessageConverter(); HttpHeaders requestHeaders = new HttpHeaders(); @@ -216,7 +210,7 @@ public class RestTemplateTests { } @Test - public void getUnsupportedMediaType() throws Exception { + void getUnsupportedMediaType() throws Exception { mockSentRequest(GET, "https://example.com/resource"); mockResponseStatus(HttpStatus.OK); @@ -235,7 +229,7 @@ public class RestTemplateTests { } @Test - public void requestAvoidsDuplicateAcceptHeaderValues() throws Exception { + void requestAvoidsDuplicateAcceptHeaderValues() throws Exception { HttpMessageConverter firstConverter = mock(HttpMessageConverter.class); given(firstConverter.canRead(any(), any())).willReturn(true); given(firstConverter.getSupportedMediaTypes()) @@ -257,7 +251,7 @@ public class RestTemplateTests { } @Test - public void getForEntity() throws Exception { + void getForEntity() throws Exception { HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(GET, "https://example.com", requestHeaders); mockTextPlainHttpMessageConverter(); @@ -275,7 +269,7 @@ public class RestTemplateTests { } @Test - public void getForObjectWithCustomUriTemplateHandler() throws Exception { + void getForObjectWithCustomUriTemplateHandler() throws Exception { DefaultUriBuilderFactory uriTemplateHandler = new DefaultUriBuilderFactory(); template.setUriTemplateHandler(uriTemplateHandler); mockSentRequest(GET, "https://example.com/hotels/1/pic/pics%2Flogo.png/size/150x150"); @@ -295,7 +289,7 @@ public class RestTemplateTests { } @Test - public void headForHeaders() throws Exception { + void headForHeaders() throws Exception { mockSentRequest(HEAD, "https://example.com"); mockResponseStatus(HttpStatus.OK); HttpHeaders responseHeaders = new HttpHeaders(); @@ -309,7 +303,7 @@ public class RestTemplateTests { } @Test - public void postForLocation() throws Exception { + void postForLocation() throws Exception { mockSentRequest(POST, "https://example.com"); mockTextPlainHttpMessageConverter(); mockResponseStatus(HttpStatus.OK); @@ -326,7 +320,7 @@ public class RestTemplateTests { } @Test - public void postForLocationEntityContentType() throws Exception { + void postForLocationEntityContentType() throws Exception { mockSentRequest(POST, "https://example.com"); mockTextPlainHttpMessageConverter(); mockResponseStatus(HttpStatus.OK); @@ -348,7 +342,7 @@ public class RestTemplateTests { } @Test - public void postForLocationEntityCustomHeader() throws Exception { + void postForLocationEntityCustomHeader() throws Exception { HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(POST, "https://example.com", requestHeaders); mockTextPlainHttpMessageConverter(); @@ -370,7 +364,7 @@ public class RestTemplateTests { } @Test - public void postForLocationNoLocation() throws Exception { + void postForLocationNoLocation() throws Exception { mockSentRequest(POST, "https://example.com"); mockTextPlainHttpMessageConverter(); mockResponseStatus(HttpStatus.OK); @@ -382,7 +376,7 @@ public class RestTemplateTests { } @Test - public void postForLocationNull() throws Exception { + void postForLocationNull() throws Exception { HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(POST, "https://example.com", requestHeaders); mockResponseStatus(HttpStatus.OK); @@ -394,7 +388,7 @@ public class RestTemplateTests { } @Test - public void postForObject() throws Exception { + void postForObject() throws Exception { mockTextPlainHttpMessageConverter(); HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(POST, "https://example.com", requestHeaders); @@ -410,7 +404,7 @@ public class RestTemplateTests { } @Test - public void postForEntity() throws Exception { + void postForEntity() throws Exception { mockTextPlainHttpMessageConverter(); HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(POST, "https://example.com", requestHeaders); @@ -428,7 +422,7 @@ public class RestTemplateTests { } @Test - public void postForObjectNull() throws Exception { + void postForObjectNull() throws Exception { mockTextPlainHttpMessageConverter(); HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(POST, "https://example.com", requestHeaders); @@ -448,7 +442,7 @@ public class RestTemplateTests { } @Test - public void postForEntityNull() throws Exception { + void postForEntityNull() throws Exception { mockTextPlainHttpMessageConverter(); HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(POST, "https://example.com", requestHeaders); @@ -470,7 +464,7 @@ public class RestTemplateTests { } @Test - public void put() throws Exception { + void put() throws Exception { mockTextPlainHttpMessageConverter(); mockSentRequest(PUT, "https://example.com"); mockResponseStatus(HttpStatus.OK); @@ -481,7 +475,7 @@ public class RestTemplateTests { } @Test - public void putNull() throws Exception { + void putNull() throws Exception { HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(PUT, "https://example.com", requestHeaders); mockResponseStatus(HttpStatus.OK); @@ -493,26 +487,21 @@ public class RestTemplateTests { } @Test // gh-23740 - public void headerAcceptAllOnPut() throws Exception { - MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error")); - server.start(); - try { + void headerAcceptAllOnPut() throws Exception { + try (MockWebServer server = new MockWebServer()) { + server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error")); + server.start(); template.setRequestFactory(new SimpleClientHttpRequestFactory()); template.put(server.url("/internal/server/error").uri(), null); assertThat(server.takeRequest().getHeader("Accept")).isEqualTo("*/*"); } - finally { - server.shutdown(); - } } @Test // gh-23740 - public void keepGivenAcceptHeaderOnPut() throws Exception { - MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error")); - server.start(); - try { + void keepGivenAcceptHeaderOnPut() throws Exception { + try (MockWebServer server = new MockWebServer()) { + server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error")); + server.start(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); HttpEntity entity = new HttpEntity<>(null, headers); @@ -530,13 +519,10 @@ public class RestTemplateTests { assertThat(accepts.get(0)).hasSize(1); assertThat(accepts.get(0).get(0)).isEqualTo("application/json"); } - finally { - server.shutdown(); - } } @Test - public void patchForObject() throws Exception { + void patchForObject() throws Exception { mockTextPlainHttpMessageConverter(); HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(PATCH, "https://example.com", requestHeaders); @@ -552,7 +538,7 @@ public class RestTemplateTests { } @Test - public void patchForObjectNull() throws Exception { + void patchForObjectNull() throws Exception { mockTextPlainHttpMessageConverter(); HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(PATCH, "https://example.com", requestHeaders); @@ -570,9 +556,8 @@ public class RestTemplateTests { verify(response).close(); } - @Test - public void delete() throws Exception { + void delete() throws Exception { mockSentRequest(DELETE, "https://example.com"); mockResponseStatus(HttpStatus.OK); @@ -582,22 +567,18 @@ public class RestTemplateTests { } @Test // gh-23740 - public void headerAcceptAllOnDelete() throws Exception { - MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error")); - server.start(); - try { + void headerAcceptAllOnDelete() throws Exception { + try (MockWebServer server = new MockWebServer()) { + server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error")); + server.start(); template.setRequestFactory(new SimpleClientHttpRequestFactory()); template.delete(server.url("/internal/server/error").uri()); assertThat(server.takeRequest().getHeader("Accept")).isEqualTo("*/*"); } - finally { - server.shutdown(); - } } @Test - public void optionsForAllow() throws Exception { + void optionsForAllow() throws Exception { mockSentRequest(OPTIONS, "https://example.com"); mockResponseStatus(HttpStatus.OK); HttpHeaders responseHeaders = new HttpHeaders(); @@ -612,7 +593,7 @@ public class RestTemplateTests { } @Test // SPR-9325, SPR-13860 - public void ioException() throws Exception { + void ioException() throws Exception { String url = "https://example.com/resource?access_token=123"; mockSentRequest(GET, url); mockHttpMessageConverter(new MediaType("foo", "bar"), String.class); @@ -625,8 +606,7 @@ public class RestTemplateTests { } @Test // SPR-15900 - public void ioExceptionWithEmptyQueryString() throws Exception { - + void ioExceptionWithEmptyQueryString() throws Exception { // https://example.com/resource? URI uri = new URI("https", "example.com", "/resource", "", null); @@ -643,7 +623,7 @@ public class RestTemplateTests { } @Test - public void exchange() throws Exception { + void exchange() throws Exception { mockTextPlainHttpMessageConverter(); HttpHeaders requestHeaders = new HttpHeaders(); mockSentRequest(POST, "https://example.com", requestHeaders); @@ -666,7 +646,7 @@ public class RestTemplateTests { @Test @SuppressWarnings("rawtypes") - public void exchangeParameterizedType() throws Exception { + void exchangeParameterizedType() throws Exception { GenericHttpMessageConverter converter = mock(GenericHttpMessageConverter.class); template.setMessageConverters(Collections.>singletonList(converter)); ParameterizedTypeReference> intList = new ParameterizedTypeReference>() {}; @@ -700,7 +680,7 @@ public class RestTemplateTests { } @Test // SPR-15066 - public void requestInterceptorCanAddExistingHeaderValueWithoutBody() throws Exception { + void requestInterceptorCanAddExistingHeaderValueWithoutBody() throws Exception { ClientHttpRequestInterceptor interceptor = (request, body, execution) -> { request.getHeaders().add("MyHeader", "MyInterceptorValue"); return execution.execute(request, body); @@ -721,7 +701,7 @@ public class RestTemplateTests { } @Test // SPR-15066 - public void requestInterceptorCanAddExistingHeaderValueWithBody() throws Exception { + void requestInterceptorCanAddExistingHeaderValueWithBody() throws Exception { ClientHttpRequestInterceptor interceptor = (request, body, execution) -> { request.getHeaders().add("MyHeader", "MyInterceptorValue"); return execution.execute(request, body); @@ -745,7 +725,7 @@ public class RestTemplateTests { } @Test - public void clientHttpRequestInitializerAndRequestInterceptorAreBothApplied() throws Exception { + void clientHttpRequestInitializerAndRequestInterceptorAreBothApplied() throws Exception { ClientHttpRequestInitializer initializer = request -> request.getHeaders().add("MyHeader", "MyInitializerValue"); ClientHttpRequestInterceptor interceptor = (request, body, execution) -> { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java index 4076f5df40..347be47f53 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java @@ -387,6 +387,7 @@ class WebClientIntegrationTests { } @ParameterizedWebClientTest + @SuppressWarnings("rawtypes") void retrieveJsonNull(ClientHttpConnector connector) { startServer(connector); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/ComplexWebApplicationContext.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/ComplexWebApplicationContext.java index bb6c58663f..9c00d19500 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/ComplexWebApplicationContext.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/ComplexWebApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -67,7 +67,6 @@ import org.springframework.web.servlet.support.RequestContextUtils; import org.springframework.web.servlet.theme.SessionThemeResolver; import org.springframework.web.servlet.theme.ThemeChangeInterceptor; import org.springframework.web.servlet.view.InternalResourceViewResolver; -import org.springframework.web.servlet.view.ResourceBundleViewResolver; import org.springframework.web.util.WebUtils; /** @@ -77,6 +76,7 @@ import org.springframework.web.util.WebUtils; public class ComplexWebApplicationContext extends StaticWebApplicationContext { @Override + @SuppressWarnings("deprecation") public void refresh() throws BeansException { registerSingleton(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, SessionLocaleResolver.class); registerSingleton(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, SessionThemeResolver.class); @@ -126,7 +126,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext { pvs = new MutablePropertyValues(); pvs.add("order", 0); pvs.add("basename", "org.springframework.web.servlet.complexviews"); - registerSingleton("viewResolver", ResourceBundleViewResolver.class, pvs); + registerSingleton("viewResolver", org.springframework.web.servlet.view.ResourceBundleViewResolver.class, pvs); pvs = new MutablePropertyValues(); pvs.add("suffix", ".jsp"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java index 3845c8a076..6c2e1ed2c0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/SimpleWebApplicationContext.java @@ -38,7 +38,6 @@ import org.springframework.web.servlet.mvc.LastModified; import org.springframework.web.servlet.support.RequestContextUtils; import org.springframework.web.servlet.theme.AbstractThemeResolver; import org.springframework.web.servlet.view.InternalResourceViewResolver; -import org.springframework.web.servlet.view.XmlViewResolver; /** * @author Juergen Hoeller @@ -47,6 +46,7 @@ import org.springframework.web.servlet.view.XmlViewResolver; public class SimpleWebApplicationContext extends StaticWebApplicationContext { @Override + @SuppressWarnings("deprecation") public void refresh() throws BeansException { registerSingleton("/locale.do", LocaleChecker.class); @@ -62,7 +62,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext { MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("location", "org/springframework/web/context/WEB-INF/sessionContext.xml"); - registerSingleton("viewResolver2", XmlViewResolver.class, pvs); + registerSingleton("viewResolver2", org.springframework.web.servlet.view.XmlViewResolver.class, pvs); super.refresh(); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParserTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParserTests.java index 932d0f24ac..4acfaf6cff 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParserTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -77,6 +77,7 @@ public class AnnotationDrivenBeanDefinitionParserTests { } @Test + @SuppressWarnings("deprecation") public void testPathMatchingConfiguration() { loadBeanDefinitions("mvc-config-path-matching.xml"); RequestMappingHandlerMapping hm = this.appContext.getBean(RequestMappingHandlerMapping.class); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java index ed22feb062..28722603a3 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java @@ -350,6 +350,7 @@ public class MvcNamespaceTests { } @Test + @SuppressWarnings("deprecation") public void testResources() throws Exception { loadBeanDefinitions("mvc-config-resources.xml"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java index 052eca7679..9393f5d6bf 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java @@ -203,12 +203,14 @@ public class DelegatingWebMvcConfigurationTests { } @Test + @SuppressWarnings("deprecation") public void configurePathMatcher() { PathMatcher pathMatcher = mock(PathMatcher.class); UrlPathHelper pathHelper = mock(UrlPathHelper.class); WebMvcConfigurer configurer = new WebMvcConfigurer() { @Override + @SuppressWarnings("deprecation") public void configurePathMatch(PathMatchConfigurer configurer) { configurer.setUseRegisteredSuffixPatternMatch(true) .setUseTrailingSlashMatch(false) 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 7df216ccae..d4bd763d6f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -177,6 +177,7 @@ public class InterceptorRegistryTests { } + @SuppressWarnings("deprecation") private List getInterceptorsForPath(String lookupPath) { PathMatcher pathMatcher = new AntPathMatcher(); List result = new ArrayList<>(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java index 9f36c0fd6d..f4055a93da 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java @@ -263,6 +263,7 @@ public class WebMvcConfigurationSupportExtensionTests { } @Test + @SuppressWarnings("deprecation") public void contentNegotiation() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json"); NativeWebRequest webRequest = new ServletWebRequest(request); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerRequestTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerRequestTests.java index 7b38b06d50..07233b27ec 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerRequestTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerRequestTests.java @@ -52,7 +52,6 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.HttpMediaTypeNotSupportedException; import org.springframework.web.servlet.handler.PathPatternsTestUtils; -import org.springframework.web.testfixture.server.MockServerWebExchange; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import org.springframework.web.testfixture.servlet.MockHttpSession; import org.springframework.web.testfixture.servlet.MockPart; @@ -61,7 +60,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.get; /** * @author Arjen Poutsma @@ -481,10 +479,6 @@ class DefaultServerRequestTests { Instant oneMinuteAgo = now.minus(1, ChronoUnit.MINUTES); servletRequest.addHeader(HttpHeaders.IF_NONE_MATCH, eTag); servletRequest.addHeader(HttpHeaders.IF_MODIFIED_SINCE, oneMinuteAgo.toEpochMilli()); - MockServerWebExchange exchange = MockServerWebExchange.from(get("/") - .ifNoneMatch(eTag) - .ifModifiedSince(oneMinuteAgo.toEpochMilli()) - ); DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java index 38693d3c47..4935fd8432 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMethodMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -42,7 +42,6 @@ import org.springframework.web.util.UrlPathHelper; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; - /** * Test for {@link AbstractHandlerMethodMapping}. * @@ -271,6 +270,7 @@ public class HandlerMethodMappingTests { } @Override + @SuppressWarnings("deprecation") protected Set getMappingPathPatterns(String key) { return (this.pathMatcher.isPattern(key) ? Collections.emptySet() : Collections.singleton(key)); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java index a6a75d0142..48522f10f5 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java @@ -93,6 +93,7 @@ public class SimpleUrlHandlerMappingTests { Object otherBean = wac.getBean("otherController"); Object defaultBean = wac.getBean("starController"); HandlerMapping hm = (HandlerMapping) wac.getBean(beanName); + wac.close(); boolean usePathPatterns = (((AbstractHandlerMapping) hm).getPatternParser() != null); MockHttpServletRequest request = PathPatternsTestUtils.initRequest("GET", "/welcome.html", usePathPatterns); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java index 02a4aa977a..7957ccb184 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java @@ -108,6 +108,7 @@ class PatternsRequestConditionTests { } @Test + @SuppressWarnings("deprecation") void matchSuffixPattern() { MockHttpServletRequest request = initRequest("/foo.html"); @@ -129,6 +130,7 @@ class PatternsRequestConditionTests { } @Test // SPR-8410 + @SuppressWarnings("deprecation") void matchSuffixPatternUsingFileExtensions() { PatternsRequestCondition condition = new PatternsRequestCondition( new String[] {"/jobs/{jobName}"}, null, null, true, false, Collections.singletonList("json")); @@ -147,6 +149,7 @@ class PatternsRequestConditionTests { } @Test + @SuppressWarnings("deprecation") void matchSuffixPatternUsingFileExtensions2() { PatternsRequestCondition condition1 = new PatternsRequestCondition( new String[] {"/prefix"}, null, null, true, false, Collections.singletonList("json")); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java index 6073c8276b..6742d39ade 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java @@ -550,6 +550,7 @@ class RequestMappingInfoHandlerMappingTests { } } + @SuppressWarnings("deprecation") private RequestMappingInfo.BuilderConfiguration getBuilderConfig() { RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration(); if (getPatternParser() != null) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMethodMappingNamingStrategyTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMethodMappingNamingStrategyTests.java index ad488765a8..e1a0018896 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMethodMappingNamingStrategyTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMethodMappingNamingStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -28,8 +28,7 @@ import org.springframework.web.servlet.handler.HandlerMethodMappingNamingStrateg import static org.assertj.core.api.Assertions.assertThat; /** - * Unit tests for - * {@link org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMethodMappingNamingStrategy}. + * Unit tests for {@link RequestMappingInfoHandlerMethodMappingNamingStrategy}. * * @author Rossen Stoyanchev */ @@ -37,10 +36,10 @@ public class RequestMappingInfoHandlerMethodMappingNamingStrategyTests { @Test public void getNameExplicit() { - Method method = ClassUtils.getMethod(TestController.class, "handle"); HandlerMethod handlerMethod = new HandlerMethod(new TestController(), method); + @SuppressWarnings("deprecation") RequestMappingInfo rmi = new RequestMappingInfo("foo", null, null, null, null, null, null, null); HandlerMethodMappingNamingStrategy strategy = new RequestMappingInfoHandlerMethodMappingNamingStrategy(); @@ -50,10 +49,10 @@ public class RequestMappingInfoHandlerMethodMappingNamingStrategyTests { @Test public void getNameConvention() { - Method method = ClassUtils.getMethod(TestController.class, "handle"); HandlerMethod handlerMethod = new HandlerMethod(new TestController(), method); + @SuppressWarnings("deprecation") RequestMappingInfo rmi = new RequestMappingInfo(null, null, null, null, null, null, null, null); HandlerMethodMappingNamingStrategy strategy = new RequestMappingInfoHandlerMethodMappingNamingStrategy(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java index 9948c24338..4985d4c176 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java @@ -82,6 +82,7 @@ class CrossOriginTests { TestRequestMappingInfoHandlerMapping mapping2 = new TestRequestMappingInfoHandlerMapping(); wac.getAutowireCapableBeanFactory().initializeBean(mapping2, "mapping2"); + wac.close(); return Stream.of(mapping1, mapping2); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java index 2238b54469..f60e69af0e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java @@ -36,7 +36,6 @@ import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.util.ClassUtils; import org.springframework.web.accept.ContentNegotiationManager; -import org.springframework.web.accept.PathExtensionContentNegotiationStrategy; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; @@ -82,13 +81,14 @@ public class RequestMappingHandlerMappingTests { @Test + @SuppressWarnings("deprecation") void useRegisteredSuffixPatternMatch() { RequestMappingHandlerMapping handlerMapping = new RequestMappingHandlerMapping(); handlerMapping.setApplicationContext(new StaticWebApplicationContext()); Map fileExtensions = Collections.singletonMap("json", MediaType.APPLICATION_JSON); - PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(fileExtensions); + org.springframework.web.accept.PathExtensionContentNegotiationStrategy strategy = new org.springframework.web.accept.PathExtensionContentNegotiationStrategy(fileExtensions); ContentNegotiationManager manager = new ContentNegotiationManager(strategy); handlerMapping.setContentNegotiationManager(manager); @@ -101,9 +101,10 @@ public class RequestMappingHandlerMappingTests { } @Test + @SuppressWarnings("deprecation") void useRegisteredSuffixPatternMatchInitialization() { Map fileExtensions = Collections.singletonMap("json", MediaType.APPLICATION_JSON); - PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(fileExtensions); + org.springframework.web.accept.PathExtensionContentNegotiationStrategy strategy = new org.springframework.web.accept.PathExtensionContentNegotiationStrategy(fileExtensions); ContentNegotiationManager manager = new ContentNegotiationManager(strategy); final Set extensions = new HashSet<>(); @@ -129,6 +130,7 @@ public class RequestMappingHandlerMappingTests { } @Test + @SuppressWarnings("deprecation") void suffixPatternMatchSettings() { RequestMappingHandlerMapping handlerMapping = new RequestMappingHandlerMapping(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java index cf00f1bf42..03a5167db9 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java @@ -242,6 +242,7 @@ public class ResourceHttpRequestHandlerTests { } @Test // SPR-13658 + @SuppressWarnings("deprecation") public void getResourceWithRegisteredMediaType() throws Exception { ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean(); factory.addMediaType("bar", new MediaType("foo", "bar")); @@ -263,6 +264,7 @@ public class ResourceHttpRequestHandlerTests { } @Test // SPR-14577 + @SuppressWarnings("deprecation") public void getMediaTypeWithFavorPathExtensionOff() throws Exception { ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean(); factory.setFavorPathExtension(false); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolverTests.java index 635c46d1c0..e3b8295dfb 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolverTests.java @@ -34,7 +34,6 @@ import org.springframework.web.accept.FixedContentNegotiationStrategy; import org.springframework.web.accept.HeaderContentNegotiationStrategy; import org.springframework.web.accept.MappingMediaTypeFileExtensionResolver; import org.springframework.web.accept.ParameterContentNegotiationStrategy; -import org.springframework.web.accept.PathExtensionContentNegotiationStrategy; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.support.StaticWebApplicationContext; @@ -332,11 +331,12 @@ public class ContentNegotiatingViewResolverTests { } @Test + @SuppressWarnings("deprecation") public void resolveViewNameFilenameDefaultView() throws Exception { request.setRequestURI("/test.json"); Map mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON); - PathExtensionContentNegotiationStrategy pathStrategy = new PathExtensionContentNegotiationStrategy(mapping); + org.springframework.web.accept.PathExtensionContentNegotiationStrategy pathStrategy = new org.springframework.web.accept.PathExtensionContentNegotiationStrategy(mapping); viewResolver.setContentNegotiationManager(new ContentNegotiationManager(pathStrategy)); ViewResolver viewResolverMock1 = mock(ViewResolver.class); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java index 6010722ad7..3e6efbb07e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ResourceBundleViewResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -42,6 +42,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; * @author Juergen Hoeller * @author Sam Brannen */ +@SuppressWarnings("deprecation") public class ResourceBundleViewResolverTests { /** Comes from this package */ diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ViewResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ViewResolverTests.java index 07fa8cfe8a..25c5a590c8 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ViewResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/view/ViewResolverTests.java @@ -57,8 +57,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Unit tests for {@link BeanNameViewResolver}, {@link UrlBasedViewResolver}, - * {@link InternalResourceViewResolver}, {@link XmlViewResolver}, and - * {@link AbstractCachingViewResolver}. + * {@link InternalResourceViewResolver}, {@link org.springframework.web.servlet.view.XmlViewResolver}, + * and {@link AbstractCachingViewResolver}. * * @author Juergen Hoeller * @author Chris Beams @@ -399,11 +399,12 @@ public class ViewResolverTests { } @Test + @SuppressWarnings("deprecation") public void xmlViewResolver() throws Exception { this.wac.registerSingleton("testBean", TestBean.class); this.wac.refresh(); TestBean testBean = (TestBean) this.wac.getBean("testBean"); - XmlViewResolver vr = new XmlViewResolver(); + org.springframework.web.servlet.view.XmlViewResolver vr = new org.springframework.web.servlet.view.XmlViewResolver(); vr.setLocation(new ClassPathResource("org/springframework/web/servlet/view/views.xml")); vr.setApplicationContext(this.wac); @@ -438,33 +439,35 @@ public class ViewResolverTests { } @Test + @SuppressWarnings("deprecation") public void xmlViewResolverDefaultLocation() { StaticWebApplicationContext wac = new StaticWebApplicationContext() { @Override protected Resource getResourceByPath(String path) { - assertThat(XmlViewResolver.DEFAULT_LOCATION.equals(path)).as("Correct default location").isTrue(); + assertThat(org.springframework.web.servlet.view.XmlViewResolver.DEFAULT_LOCATION.equals(path)).as("Correct default location").isTrue(); return super.getResourceByPath(path); } }; wac.setServletContext(this.sc); wac.refresh(); - XmlViewResolver vr = new XmlViewResolver(); + org.springframework.web.servlet.view.XmlViewResolver vr = new org.springframework.web.servlet.view.XmlViewResolver(); vr.setApplicationContext(wac); assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(vr::afterPropertiesSet); } @Test + @SuppressWarnings("deprecation") public void xmlViewResolverWithoutCache() throws Exception { StaticWebApplicationContext wac = new StaticWebApplicationContext() { @Override protected Resource getResourceByPath(String path) { - assertThat(XmlViewResolver.DEFAULT_LOCATION.equals(path)).as("Correct default location").isTrue(); + assertThat(org.springframework.web.servlet.view.XmlViewResolver.DEFAULT_LOCATION.equals(path)).as("Correct default location").isTrue(); return super.getResourceByPath(path); } }; wac.setServletContext(this.sc); wac.refresh(); - XmlViewResolver vr = new XmlViewResolver(); + org.springframework.web.servlet.view.XmlViewResolver vr = new org.springframework.web.servlet.view.XmlViewResolver(); vr.setCache(false); vr.setApplicationContext(wac); assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java index 8c2cab0ec6..ea48d984ee 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java @@ -72,20 +72,19 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { @ParameterizedWebSocketTest - @SuppressWarnings("try") void sendMessageToController(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception { super.setup(server, webSocketClient, testInfo); TextMessage message = create(StompCommand.SEND).headers("destination:/app/simple").build(); - try (@SuppressWarnings("unused")WebSocketSession session = doHandshake(new TestClientWebSocketHandler(0, message), "/ws").get()) { + try (WebSocketSession session = doHandshake(new TestClientWebSocketHandler(0, message), "/ws").get()) { + assertThat(session).isNotNull(); SimpleController controller = this.wac.getBean(SimpleController.class); assertThat(controller.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue(); } } @ParameterizedWebSocketTest - @SuppressWarnings("try") void sendMessageToControllerAndReceiveReplyViaTopic(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception { super.setup(server, webSocketClient, testInfo); @@ -98,12 +97,12 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { TestClientWebSocketHandler clientHandler = new TestClientWebSocketHandler(2, m0, m1, m2); try (WebSocketSession session = doHandshake(clientHandler, "/ws").get()) { + assertThat(session).isNotNull(); assertThat(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue(); } } @ParameterizedWebSocketTest // SPR-10930 - @SuppressWarnings("try") void sendMessageToBrokerAndReceiveReplyViaTopic(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception { super.setup(server, webSocketClient, testInfo); @@ -114,6 +113,7 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { TestClientWebSocketHandler clientHandler = new TestClientWebSocketHandler(2, m0, m1, m2); try (WebSocketSession session = doHandshake(clientHandler, "/ws").get()) { + assertThat(session).isNotNull(); assertThat(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue(); String payload = clientHandler.actual.get(1).getPayload(); @@ -122,7 +122,6 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { } @ParameterizedWebSocketTest // SPR-11648 - @SuppressWarnings("try") void sendSubscribeToControllerAndReceiveReply(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception { super.setup(server, webSocketClient, testInfo); @@ -133,6 +132,7 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { TestClientWebSocketHandler clientHandler = new TestClientWebSocketHandler(2, m0, m1); try (WebSocketSession session = doHandshake(clientHandler, "/ws").get()) { + assertThat(session).isNotNull(); assertThat(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue(); String payload = clientHandler.actual.get(1).getPayload(); assertThat(payload.contains(destHeader)).as("Expected STOMP destination=/app/number, got " + payload).isTrue(); @@ -141,7 +141,6 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { } @ParameterizedWebSocketTest - @SuppressWarnings("try") void handleExceptionAndSendToUser(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception { super.setup(server, webSocketClient, testInfo); @@ -153,6 +152,7 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { TestClientWebSocketHandler clientHandler = new TestClientWebSocketHandler(2, m0, m1, m2); try (WebSocketSession session = doHandshake(clientHandler, "/ws").get()) { + assertThat(session).isNotNull(); assertThat(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue(); String payload = clientHandler.actual.get(1).getPayload(); assertThat(payload.startsWith("MESSAGE\n")).isTrue(); @@ -162,7 +162,6 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { } @ParameterizedWebSocketTest - @SuppressWarnings("try") void webSocketScope(WebSocketTestServer server, WebSocketClient webSocketClient, TestInfo testInfo) throws Exception { super.setup(server, webSocketClient, testInfo); @@ -175,6 +174,7 @@ class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { TestClientWebSocketHandler clientHandler = new TestClientWebSocketHandler(2, m0, m1, m2); try (WebSocketSession session = doHandshake(clientHandler, "/ws").get()) { + assertThat(session).isNotNull(); assertThat(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue(); String payload = clientHandler.actual.get(1).getPayload(); assertThat(payload.startsWith("MESSAGE\n")).isTrue();