diff --git a/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java b/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java index 82c092301e2..2f5a1d8eca9 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/context/ContextLoaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -232,7 +232,7 @@ class ContextLoaderTests { } @Test - void contextLoaderWithCustomContext() throws Exception { + void contextLoaderWithCustomContext() { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, "org.springframework.web.servlet.SimpleWebApplicationContext"); @@ -246,7 +246,7 @@ class ContextLoaderTests { } @Test - void contextLoaderWithInvalidLocation() throws Exception { + void contextLoaderWithInvalidLocation() { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "/WEB-INF/myContext.xml"); ServletContextListener listener = new ContextLoaderListener(); @@ -257,7 +257,7 @@ class ContextLoaderTests { } @Test - void contextLoaderWithInvalidContext() throws Exception { + void contextLoaderWithInvalidContext() { MockServletContext sc = new MockServletContext(""); sc.addInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, "org.springframework.web.context.support.InvalidWebApplicationContext"); @@ -269,7 +269,7 @@ class ContextLoaderTests { } @Test - void contextLoaderWithDefaultLocation() throws Exception { + void contextLoaderWithDefaultLocation() { MockServletContext sc = new MockServletContext(""); ServletContextListener listener = new ContextLoaderListener(); ServletContextEvent event = new ServletContextEvent(sc); @@ -281,7 +281,7 @@ class ContextLoaderTests { } @Test - void frameworkServletWithDefaultLocation() throws Exception { + void frameworkServletWithDefaultLocation() { DispatcherServlet servlet = new DispatcherServlet(); servlet.setContextClass(XmlWebApplicationContext.class); assertThatExceptionOfType(BeanDefinitionStoreException.class) @@ -302,8 +302,7 @@ class ContextLoaderTests { } @Test - @SuppressWarnings("resource") - void classPathXmlApplicationContext() throws IOException { + void classPathXmlApplicationContext() { ApplicationContext context = new ClassPathXmlApplicationContext( "/org/springframework/web/context/WEB-INF/applicationContext.xml"); assertThat(context.containsBean("father")).as("Has father").isTrue(); @@ -312,17 +311,16 @@ class ContextLoaderTests { assertThat(((TestBean) context.getBean("rod")).getSpouse()).as("Doesn't have spouse").isNull(); assertThat(((TestBean) context.getBean("rod")).getName()).as("myinit not evaluated").isEqualTo("Roderick"); - context = new ClassPathXmlApplicationContext(new String[] { - "/org/springframework/web/context/WEB-INF/applicationContext.xml", - "/org/springframework/web/context/WEB-INF/context-addition.xml" }); + context = new ClassPathXmlApplicationContext( + "/org/springframework/web/context/WEB-INF/applicationContext.xml", + "/org/springframework/web/context/WEB-INF/context-addition.xml"); assertThat(context.containsBean("father")).as("Has father").isTrue(); assertThat(context.containsBean("rod")).as("Has rod").isTrue(); assertThat(context.containsBean("kerry")).as("Has kerry").isTrue(); } @Test - @SuppressWarnings("resource") - void singletonDestructionOnStartupFailure() throws IOException { + void singletonDestructionOnStartupFailure() { assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> new ClassPathXmlApplicationContext(new String[] { "/org/springframework/web/context/WEB-INF/applicationContext.xml", diff --git a/spring-webmvc/src/test/java/org/springframework/web/context/ServletContextAwareProcessorTests.java b/spring-webmvc/src/test/java/org/springframework/web/context/ServletContextAwareProcessorTests.java index 0bba426369d..cb319c67a94 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/context/ServletContextAwareProcessorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/context/ServletContextAwareProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Juergen Hoeller * @author Mark Fisher */ -public class ServletContextAwareProcessorTests { +class ServletContextAwareProcessorTests { @Test - public void servletContextAwareWithServletContext() { + void servletContextAwareWithServletContext() { ServletContext servletContext = new MockServletContext(); ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext); ServletContextAwareBean bean = new ServletContextAwareBean(); @@ -44,7 +44,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletContextAwareWithServletConfig() { + void servletContextAwareWithServletConfig() { ServletContext servletContext = new MockServletContext(); ServletConfig servletConfig = new MockServletConfig(servletContext); ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletConfig); @@ -56,7 +56,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletContextAwareWithServletContextAndServletConfig() { + void servletContextAwareWithServletContextAndServletConfig() { ServletContext servletContext = new MockServletContext(); ServletConfig servletConfig = new MockServletConfig(servletContext); ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, servletConfig); @@ -68,7 +68,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletContextAwareWithNullServletContextAndNonNullServletConfig() { + void servletContextAwareWithNullServletContextAndNonNullServletConfig() { ServletContext servletContext = new MockServletContext(); ServletConfig servletConfig = new MockServletConfig(servletContext); ServletContextAwareProcessor processor = new ServletContextAwareProcessor(null, servletConfig); @@ -80,7 +80,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletContextAwareWithNonNullServletContextAndNullServletConfig() { + void servletContextAwareWithNonNullServletContextAndNullServletConfig() { ServletContext servletContext = new MockServletContext(); ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, null); ServletContextAwareBean bean = new ServletContextAwareBean(); @@ -91,7 +91,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletContextAwareWithNullServletContext() { + void servletContextAwareWithNullServletContext() { ServletContext servletContext = null; ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext); ServletContextAwareBean bean = new ServletContextAwareBean(); @@ -101,7 +101,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletConfigAwareWithServletContextOnly() { + void servletConfigAwareWithServletContextOnly() { ServletContext servletContext = new MockServletContext(); ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext); ServletConfigAwareBean bean = new ServletConfigAwareBean(); @@ -111,7 +111,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletConfigAwareWithServletConfig() { + void servletConfigAwareWithServletConfig() { ServletContext servletContext = new MockServletContext(); ServletConfig servletConfig = new MockServletConfig(servletContext); ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletConfig); @@ -123,7 +123,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletConfigAwareWithServletContextAndServletConfig() { + void servletConfigAwareWithServletContextAndServletConfig() { ServletContext servletContext = new MockServletContext(); ServletConfig servletConfig = new MockServletConfig(servletContext); ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, servletConfig); @@ -135,7 +135,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletConfigAwareWithNullServletContextAndNonNullServletConfig() { + void servletConfigAwareWithNullServletContextAndNonNullServletConfig() { ServletContext servletContext = new MockServletContext(); ServletConfig servletConfig = new MockServletConfig(servletContext); ServletContextAwareProcessor processor = new ServletContextAwareProcessor(null, servletConfig); @@ -147,7 +147,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletConfigAwareWithNonNullServletContextAndNullServletConfig() { + void servletConfigAwareWithNonNullServletContextAndNullServletConfig() { ServletContext servletContext = new MockServletContext(); ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext, null); ServletConfigAwareBean bean = new ServletConfigAwareBean(); @@ -157,7 +157,7 @@ public class ServletContextAwareProcessorTests { } @Test - public void servletConfigAwareWithNullServletContext() { + void servletConfigAwareWithNullServletContext() { ServletContext servletContext = null; ServletContextAwareProcessor processor = new ServletContextAwareProcessor(servletContext); ServletConfigAwareBean bean = new ServletConfigAwareBean(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/context/XmlWebApplicationContextTests.java b/spring-webmvc/src/test/java/org/springframework/web/context/XmlWebApplicationContextTests.java index 8f1dca1d460..b0a05b045a0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/context/XmlWebApplicationContextTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/context/XmlWebApplicationContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -18,7 +18,6 @@ package org.springframework.web.context; import java.util.Locale; -import jakarta.servlet.ServletException; import org.junit.jupiter.api.Test; import org.springframework.beans.BeansException; @@ -41,12 +40,12 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Rod Johnson * @author Juergen Hoeller */ -public class XmlWebApplicationContextTests extends AbstractApplicationContextTests { +class XmlWebApplicationContextTests extends AbstractApplicationContextTests { private ConfigurableWebApplicationContext root; @Override - protected ConfigurableApplicationContext createContext() throws Exception { + protected ConfigurableApplicationContext createContext() { InitAndIB.constructed = false; root = new XmlWebApplicationContext(); root.getEnvironment().addActiveProfile("rootProfile1"); @@ -101,8 +100,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes } @Test - @SuppressWarnings("resource") - public void withoutMessageSource() throws Exception { + public void withoutMessageSource() { MockServletContext sc = new MockServletContext(""); XmlWebApplicationContext wac = new XmlWebApplicationContext(); wac.setParent(root); @@ -117,7 +115,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes } @Test - public void contextNesting() { + void contextNesting() { TestBean father = (TestBean) this.applicationContext.getBean("father"); assertThat(father).as("Bean from root context").isNotNull(); assertThat(father.getFriends().contains("myFriend")).as("Custom BeanPostProcessor applied").isTrue(); @@ -133,7 +131,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes } @Test - public void initializingBeanAndInitMethod() throws Exception { + void initializingBeanAndInitMethod() { assertThat(InitAndIB.constructed).isFalse(); InitAndIB iib = (InitAndIB) this.applicationContext.getBean("init-and-ib"); assertThat(InitAndIB.constructed).isTrue(); @@ -166,7 +164,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes } /** Init method */ - public void customInit() throws ServletException { + public void customInit() { assertThat(this.afterPropertiesSetInvoked).isTrue(); this.initMethodInvoked = true; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/context/support/HttpRequestHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/context/support/HttpRequestHandlerTests.java index 7a5d2a36f5e..e73d9850c46 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/context/support/HttpRequestHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/context/support/HttpRequestHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -38,10 +38,10 @@ import static org.assertj.core.api.Assertions.assertThatIOException; * @author Chris Beams * @since 2.0 */ -public class HttpRequestHandlerTests { +class HttpRequestHandlerTests { @Test - public void testHttpRequestHandlerServletPassThrough() throws Exception { + void testHttpRequestHandlerServletPassThrough() throws Exception { MockServletContext servletContext = new MockServletContext(); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/context/support/ServletContextSupportTests.java b/spring-webmvc/src/test/java/org/springframework/web/context/support/ServletContextSupportTests.java index eebb41ce852..fdb5b2959b1 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/context/support/ServletContextSupportTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/context/support/ServletContextSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -41,10 +41,9 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Chris Beams * @since 22.12.2004 */ -public class ServletContextSupportTests { +class ServletContextSupportTests { @Test - @SuppressWarnings("resource") public void testServletContextAttributeFactoryBean() { MockServletContext sc = new MockServletContext(); sc.setAttribute("myAttr", "myValue"); @@ -61,7 +60,6 @@ public class ServletContextSupportTests { } @Test - @SuppressWarnings("resource") public void testServletContextAttributeFactoryBeanWithAttributeNotFound() { MockServletContext sc = new MockServletContext(); @@ -78,7 +76,6 @@ public class ServletContextSupportTests { } @Test - @SuppressWarnings("resource") public void testServletContextParameterFactoryBean() { MockServletContext sc = new MockServletContext(); sc.addInitParameter("myParam", "myValue"); @@ -95,7 +92,6 @@ public class ServletContextSupportTests { } @Test - @SuppressWarnings("resource") public void testServletContextParameterFactoryBeanWithAttributeNotFound() { MockServletContext sc = new MockServletContext(); @@ -112,7 +108,7 @@ public class ServletContextSupportTests { } @Test - public void testServletContextAttributeExporter() { + void testServletContextAttributeExporter() { TestBean tb = new TestBean(); Map attributes = new HashMap<>(); attributes.put("attr1", "value1"); @@ -128,7 +124,7 @@ public class ServletContextSupportTests { } @Test - public void testServletContextResourceLoader() { + void testServletContextResourceLoader() { MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context"); ServletContextResourceLoader rl = new ServletContextResourceLoader(sc); assertThat(rl.getResource("/WEB-INF/web.xml").exists()).isTrue(); @@ -138,7 +134,7 @@ public class ServletContextSupportTests { } @Test - public void testServletContextResourcePatternResolver() throws IOException { + void testServletContextResourcePatternResolver() throws IOException { final Set paths = new HashSet<>(); paths.add("/WEB-INF/context1.xml"); paths.add("/WEB-INF/context2.xml"); @@ -165,7 +161,7 @@ public class ServletContextSupportTests { } @Test - public void testServletContextResourcePatternResolverWithPatternPath() throws IOException { + void testServletContextResourcePatternResolverWithPatternPath() throws IOException { final Set dirs = new HashSet<>(); dirs.add("/WEB-INF/mydir1/"); dirs.add("/WEB-INF/mydir2/"); @@ -198,7 +194,7 @@ public class ServletContextSupportTests { } @Test - public void testServletContextResourcePatternResolverWithUnboundedPatternPath() throws IOException { + void testServletContextResourcePatternResolverWithUnboundedPatternPath() throws IOException { final Set dirs = new HashSet<>(); dirs.add("/WEB-INF/mydir1/"); dirs.add("/WEB-INF/mydir2/"); @@ -239,7 +235,7 @@ public class ServletContextSupportTests { } @Test - public void testServletContextResourcePatternResolverWithAbsolutePaths() throws IOException { + void testServletContextResourcePatternResolverWithAbsolutePaths() throws IOException { final Set paths = new HashSet<>(); paths.add("C:/webroot/WEB-INF/context1.xml"); paths.add("C:/webroot/WEB-INF/context2.xml"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/context/support/WebApplicationObjectSupportTests.java b/spring-webmvc/src/test/java/org/springframework/web/context/support/WebApplicationObjectSupportTests.java index 7bd06e52e6f..a8ecafbfe95 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/context/support/WebApplicationObjectSupportTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/context/support/WebApplicationObjectSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -33,10 +33,9 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Chris Beams * @since 28.08.2003 */ -public class WebApplicationObjectSupportTests { +class WebApplicationObjectSupportTests { @Test - @SuppressWarnings("resource") public void testWebApplicationObjectSupport() { StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(new MockServletContext()); @@ -50,7 +49,6 @@ public class WebApplicationObjectSupportTests { } @Test - @SuppressWarnings("resource") public void testWebApplicationObjectSupportWithWrongContext() { StaticApplicationContext ac = new StaticApplicationContext(); ac.registerBeanDefinition("test", new RootBeanDefinition(TestWebApplicationObject.class)); 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 c2119382080..cd5f19bfc93 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-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -275,7 +275,6 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext { } @Override - @SuppressWarnings("deprecation") public long getLastModified(HttpServletRequest request, Object delegate) { return ((MyHandler) delegate).lastModified(); } @@ -296,7 +295,6 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext { } @Override - @SuppressWarnings("deprecation") public long getLastModified(HttpServletRequest request, Object delegate) { return -1; } @@ -407,12 +405,12 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext { } @Override - public void postHandle(WebRequest request, @Nullable ModelMap model) throws Exception { + public void postHandle(WebRequest request, @Nullable ModelMap model) { request.setAttribute("test3x", "test3x", WebRequest.SCOPE_REQUEST); } @Override - public void afterCompletion(WebRequest request, @Nullable Exception ex) throws Exception { + public void afterCompletion(WebRequest request, @Nullable Exception ex) { request.setAttribute("test3y", "test3y", WebRequest.SCOPE_REQUEST); } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java index 1a09a5a0b24..65867661a49 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -84,7 +84,7 @@ import static org.mockito.Mockito.verify; * @author Rob Harrop * @author Sam Brannen */ -public class DispatcherServletTests { +class DispatcherServletTests { private static final String URL_KNOWN_ONLY_PARENT = "/knownOnlyToParent.do"; @@ -96,7 +96,7 @@ public class DispatcherServletTests { @BeforeEach - public void setup() throws ServletException { + void setup() throws ServletException { MockServletConfig complexConfig = new MockServletConfig(getServletContext(), "complex"); complexConfig.addInitParameter("publishContext", "false"); complexConfig.addInitParameter("class", "notWritable"); @@ -560,7 +560,7 @@ public class DispatcherServletTests { } @Test - void notDetectAllHandlerExceptionResolvers() throws ServletException, IOException { + void notDetectAllHandlerExceptionResolvers() throws ServletException { DispatcherServlet complexDispatcherServlet = new DispatcherServlet(); complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class); complexDispatcherServlet.setNamespace("test"); @@ -575,7 +575,7 @@ public class DispatcherServletTests { } @Test - void notDetectAllViewResolvers() throws ServletException, IOException { + void notDetectAllViewResolvers() throws ServletException { DispatcherServlet complexDispatcherServlet = new DispatcherServlet(); complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class); complexDispatcherServlet.setNamespace("test"); @@ -710,7 +710,7 @@ public class DispatcherServletTests { } @Test - void withNoViewAndSamePath() throws Exception { + void withNoViewAndSamePath() { InternalResourceViewResolver vr = (InternalResourceViewResolver) complexDispatcherServlet .getWebApplicationContext().getBean("viewResolver2"); vr.setSuffix(""); @@ -817,7 +817,6 @@ public class DispatcherServletTests { assertThatIllegalArgumentException().as("non-configurable Environment").isThrownBy(() -> servlet.setEnvironment(new DummyEnvironment())); class CustomServletEnvironment extends StandardServletEnvironment { } - @SuppressWarnings("serial") DispatcherServlet custom = new DispatcherServlet() { @Override protected ConfigurableWebEnvironment createEnvironment() { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/FlashMapTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/FlashMapTests.java index 0f96dd988e8..9c7504d30ab 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/FlashMapTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/FlashMapTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,10 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class FlashMapTests { +class FlashMapTests { @Test - public void isExpired() throws InterruptedException { + void isExpired() throws InterruptedException { assertThat(new FlashMap().isExpired()).isFalse(); FlashMap flashMap = new FlashMap(); @@ -42,7 +42,7 @@ public class FlashMapTests { } @Test - public void notExpired() throws InterruptedException { + void notExpired() throws InterruptedException { FlashMap flashMap = new FlashMap(); flashMap.startExpirationPeriod(10); Thread.sleep(100); @@ -51,7 +51,7 @@ public class FlashMapTests { } @Test - public void compareTo() { + void compareTo() { FlashMap flashMap1 = new FlashMap(); FlashMap flashMap2 = new FlashMap(); assertThat(flashMap1.compareTo(flashMap2)).isEqualTo(0); @@ -72,7 +72,7 @@ public class FlashMapTests { } @Test - public void addTargetRequestParamNullValue() { + void addTargetRequestParamNullValue() { FlashMap flashMap = new FlashMap(); flashMap.addTargetRequestParam("text", "abc"); flashMap.addTargetRequestParam("empty", " "); @@ -83,7 +83,7 @@ public class FlashMapTests { } @Test - public void addTargetRequestParamsNullValue() { + void addTargetRequestParamsNullValue() { MultiValueMap params = new LinkedMultiValueMap<>(); params.add("key", "abc"); params.add("key", " "); @@ -98,7 +98,7 @@ public class FlashMapTests { } @Test - public void addTargetRequestParamNullKey() { + void addTargetRequestParamNullKey() { FlashMap flashMap = new FlashMap(); flashMap.addTargetRequestParam(" ", "abc"); flashMap.addTargetRequestParam(null, "abc"); @@ -107,7 +107,7 @@ public class FlashMapTests { } @Test - public void addTargetRequestParamsNullKey() { + void addTargetRequestParamsNullKey() { MultiValueMap params = new LinkedMultiValueMap<>(); params.add(" ", "abc"); params.add(null, " "); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/HandlerExecutionChainTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/HandlerExecutionChainTests.java index 474cf12eaa5..a128330ab54 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/HandlerExecutionChainTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/HandlerExecutionChainTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -96,7 +96,7 @@ class HandlerExecutionChainTests { } @Test - void exceptionBeforePreHandle() throws Exception { + void exceptionBeforePreHandle() { this.chain.triggerAfterCompletion(this.request, this.response, null); verifyNoInteractions(this.interceptor1, this.interceptor2, this.interceptor3); } 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 0de974e4a2b..f1244366a35 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -94,7 +94,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext { public static class DummyThemeSource implements ThemeSource { - private StaticMessageSource messageSource; + private final StaticMessageSource messageSource; public DummyThemeSource() { this.messageSource = new StaticMessageSource(); 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 a88ff12ff52..42de3720f38 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-2023 the original author or authors. + * Copyright 2002-2024 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,12 +59,12 @@ import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN; * @author Brian Clozel * @author Agim Emruli */ -public class AnnotationDrivenBeanDefinitionParserTests { +class AnnotationDrivenBeanDefinitionParserTests { private final GenericWebApplicationContext appContext = new GenericWebApplicationContext(); @Test - public void testMessageCodesResolver() { + void testMessageCodesResolver() { loadBeanDefinitions("mvc-config-message-codes-resolver.xml"); RequestMappingHandlerAdapter adapter = this.appContext.getBean(RequestMappingHandlerAdapter.class); assertThat(adapter).isNotNull(); @@ -94,7 +94,7 @@ public class AnnotationDrivenBeanDefinitionParserTests { } @Test - public void testMessageConverters() { + void testMessageConverters() { loadBeanDefinitions("mvc-config-message-converters.xml"); verifyMessageConverters(this.appContext.getBean(RequestMappingHandlerAdapter.class), true); verifyMessageConverters(this.appContext.getBean(ExceptionHandlerExceptionResolver.class), true); @@ -103,14 +103,14 @@ public class AnnotationDrivenBeanDefinitionParserTests { } @Test - public void testMessageConvertersWithoutDefaultRegistrations() { + void testMessageConvertersWithoutDefaultRegistrations() { loadBeanDefinitions("mvc-config-message-converters-defaults-off.xml"); verifyMessageConverters(this.appContext.getBean(RequestMappingHandlerAdapter.class), false); verifyMessageConverters(this.appContext.getBean(ExceptionHandlerExceptionResolver.class), false); } @Test - public void testArgumentResolvers() { + void testArgumentResolvers() { loadBeanDefinitions("mvc-config-argument-resolvers.xml"); testArgumentResolvers(this.appContext.getBean(RequestMappingHandlerAdapter.class)); testArgumentResolvers(this.appContext.getBean(ExceptionHandlerExceptionResolver.class)); @@ -131,7 +131,7 @@ public class AnnotationDrivenBeanDefinitionParserTests { } @Test - public void testReturnValueHandlers() { + void testReturnValueHandlers() { loadBeanDefinitions("mvc-config-return-value-handlers.xml"); testReturnValueHandlers(this.appContext.getBean(RequestMappingHandlerAdapter.class)); testReturnValueHandlers(this.appContext.getBean(ExceptionHandlerExceptionResolver.class)); @@ -151,7 +151,7 @@ public class AnnotationDrivenBeanDefinitionParserTests { } @Test - public void beanNameUrlHandlerMapping() { + void beanNameUrlHandlerMapping() { loadBeanDefinitions("mvc-config.xml"); BeanNameUrlHandlerMapping mapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class); assertThat(mapping).isNotNull(); 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 379384ad78a..17c32edc9d5 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -179,7 +179,7 @@ public class MvcNamespaceTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { TestMockServletContext servletContext = new TestMockServletContext(); appContext = new XmlWebApplicationContext(); appContext.setServletContext(servletContext); @@ -195,7 +195,7 @@ public class MvcNamespaceTests { @Test - public void testDefaultConfig() throws Exception { + void testDefaultConfig() throws Exception { loadBeanDefinitions("mvc-config.xml"); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); @@ -272,7 +272,7 @@ public class MvcNamespaceTests { } @Test // gh-25290 - public void testDefaultConfigWithBeansInParentContext() throws Exception { + public void testDefaultConfigWithBeansInParentContext() { StaticApplicationContext parent = new StaticApplicationContext(); parent.registerSingleton("localeResolver", CookieLocaleResolver.class); parent.registerSingleton("themeResolver", CookieThemeResolver.class); @@ -289,7 +289,7 @@ public class MvcNamespaceTests { } @Test - public void testCustomConversionService() throws Exception { + void testCustomConversionService() throws Exception { loadBeanDefinitions("mvc-config-custom-conversion-service.xml"); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); @@ -316,7 +316,7 @@ public class MvcNamespaceTests { } @Test - public void testCustomValidator() throws Exception { + void testCustomValidator() throws Exception { doTestCustomValidator("mvc-config-custom-validator.xml"); } @@ -342,7 +342,7 @@ public class MvcNamespaceTests { } @Test - public void testInterceptors() throws Exception { + void testInterceptors() throws Exception { loadBeanDefinitions("mvc-config-interceptors.xml"); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); @@ -424,7 +424,7 @@ public class MvcNamespaceTests { } @Test - public void testResourcesWithOptionalAttributes() throws Exception { + void testResourcesWithOptionalAttributes() { loadBeanDefinitions("mvc-config-resources-optional-attrs.xml"); SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class); @@ -439,8 +439,7 @@ public class MvcNamespaceTests { } @Test - @SuppressWarnings("deprecation") - public void testResourcesWithResolversTransformers() throws Exception { + public void testResourcesWithResolversTransformers() { loadBeanDefinitions("mvc-config-resources-chain.xml"); SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class); @@ -485,8 +484,7 @@ public class MvcNamespaceTests { } @Test - @SuppressWarnings("deprecation") - public void testResourcesWithResolversTransformersCustom() throws Exception { + public void testResourcesWithResolversTransformersCustom() { loadBeanDefinitions("mvc-config-resources-chain-no-auto.xml"); SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class); @@ -518,7 +516,7 @@ public class MvcNamespaceTests { } @Test - public void testDefaultServletHandler() throws Exception { + void testDefaultServletHandler() throws Exception { loadBeanDefinitions("mvc-config-default-servlet.xml"); HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class); @@ -544,7 +542,7 @@ public class MvcNamespaceTests { } @Test - public void testDefaultServletHandlerWithOptionalAttributes() throws Exception { + void testDefaultServletHandlerWithOptionalAttributes() throws Exception { loadBeanDefinitions("mvc-config-default-servlet-optional-attrs.xml"); HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class); @@ -570,7 +568,7 @@ public class MvcNamespaceTests { } @Test - public void testBeanDecoration() throws Exception { + void testBeanDecoration() throws Exception { loadBeanDefinitions("mvc-config-bean-decoration.xml"); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); @@ -591,7 +589,7 @@ public class MvcNamespaceTests { } @Test - public void testViewControllers() throws Exception { + void testViewControllers() throws Exception { loadBeanDefinitions("mvc-config-view-controllers.xml"); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); @@ -672,7 +670,7 @@ public class MvcNamespaceTests { /** WebSphere gives trailing servlet path slashes by default!! */ @Test - public void testViewControllersOnWebSphere() throws Exception { + void testViewControllersOnWebSphere() throws Exception { loadBeanDefinitions("mvc-config-view-controllers.xml"); SimpleUrlHandlerMapping mapping2 = appContext.getBean(SimpleUrlHandlerMapping.class); @@ -717,7 +715,7 @@ public class MvcNamespaceTests { } @Test - public void testViewControllersDefaultConfig() { + void testViewControllersDefaultConfig() { loadBeanDefinitions("mvc-config-view-controllers-minimal.xml"); SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class); @@ -740,7 +738,7 @@ public class MvcNamespaceTests { } @Test - public void testContentNegotiationManager() throws Exception { + void testContentNegotiationManager() throws Exception { loadBeanDefinitions("mvc-config-content-negotiation-manager.xml"); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); @@ -765,7 +763,7 @@ public class MvcNamespaceTests { } @Test - public void testAsyncSupportOptions() throws Exception { + void testAsyncSupportOptions() { loadBeanDefinitions("mvc-config-async-support.xml"); RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class); @@ -785,7 +783,7 @@ public class MvcNamespaceTests { } @Test - public void testViewResolution() throws Exception { + void testViewResolution() { loadBeanDefinitions("mvc-config-view-resolution.xml"); ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class); @@ -850,7 +848,7 @@ public class MvcNamespaceTests { } @Test - public void testViewResolutionWithContentNegotiation() throws Exception { + void testViewResolutionWithContentNegotiation() { loadBeanDefinitions("mvc-config-view-resolution-content-negotiation.xml"); ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class); @@ -874,7 +872,7 @@ public class MvcNamespaceTests { } @Test - public void testViewResolutionWithOrderSet() throws Exception { + void testViewResolutionWithOrderSet() { loadBeanDefinitions("mvc-config-view-resolution-custom-order.xml"); ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class); @@ -884,7 +882,7 @@ public class MvcNamespaceTests { } @Test - public void testPathMatchingHandlerMappings() throws Exception { + void testPathMatchingHandlerMappings() { loadBeanDefinitions("mvc-config-path-matching-mappings.xml"); RequestMappingHandlerMapping requestMapping = appContext.getBean(RequestMappingHandlerMapping.class); @@ -905,7 +903,7 @@ public class MvcNamespaceTests { } @Test - public void testCorsMinimal() throws Exception { + void testCorsMinimal() { loadBeanDefinitions("mvc-config-cors-minimal.xml"); String[] beanNames = appContext.getBeanNamesForType(AbstractHandlerMapping.class); @@ -930,7 +928,7 @@ public class MvcNamespaceTests { } @Test - public void testCors() { + void testCors() { loadBeanDefinitions("mvc-config-cors.xml"); String[] beanNames = appContext.getBeanNamesForType(AbstractHandlerMapping.class); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurerTests.java index 63ff7e993d1..3a6a1686d47 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Test fixture for {@link ContentNegotiationConfigurer} tests. * @author Rossen Stoyanchev */ -public class ContentNegotiationConfigurerTests { +class ContentNegotiationConfigurerTests { private ContentNegotiationConfigurer configurer; @@ -46,7 +46,7 @@ public class ContentNegotiationConfigurerTests { @BeforeEach - public void setup() { + void setup() { this.servletRequest = new MockHttpServletRequest(); this.webRequest = new ServletWebRequest(this.servletRequest); this.configurer = new ContentNegotiationConfigurer(this.servletRequest.getServletContext()); @@ -54,7 +54,7 @@ public class ContentNegotiationConfigurerTests { @Test - public void defaultSettings() throws Exception { + void defaultSettings() throws Exception { ContentNegotiationManager manager = this.configurer.buildContentNegotiationManager(); this.servletRequest.setRequestURI("/flower.gif"); @@ -79,7 +79,7 @@ public class ContentNegotiationConfigurerTests { } @Test - public void addMediaTypes() throws Exception { + void addMediaTypes() throws Exception { this.configurer.favorParameter(true); this.configurer.mediaTypes(Collections.singletonMap("json", MediaType.APPLICATION_JSON)); ContentNegotiationManager manager = this.configurer.buildContentNegotiationManager(); @@ -90,7 +90,7 @@ public class ContentNegotiationConfigurerTests { } @Test - public void favorParameter() throws Exception { + void favorParameter() throws Exception { this.configurer.favorParameter(true); this.configurer.parameterName("f"); this.configurer.mediaTypes(Collections.singletonMap("json", MediaType.APPLICATION_JSON)); @@ -103,7 +103,7 @@ public class ContentNegotiationConfigurerTests { } @Test - public void ignoreAcceptHeader() throws Exception { + void ignoreAcceptHeader() throws Exception { this.configurer.ignoreAcceptHeader(true); this.configurer.favorParameter(true); ContentNegotiationManager manager = this.configurer.buildContentNegotiationManager(); @@ -115,7 +115,7 @@ public class ContentNegotiationConfigurerTests { } @Test - public void setDefaultContentType() throws Exception { + void setDefaultContentType() throws Exception { this.configurer.defaultContentType(MediaType.APPLICATION_JSON); ContentNegotiationManager manager = this.configurer.buildContentNegotiationManager(); @@ -123,7 +123,7 @@ public class ContentNegotiationConfigurerTests { } @Test - public void setMultipleDefaultContentTypes() throws Exception { + void setMultipleDefaultContentTypes() throws Exception { this.configurer.defaultContentType(MediaType.APPLICATION_JSON, MediaType.ALL); ContentNegotiationManager manager = this.configurer.buildContentNegotiationManager(); @@ -131,7 +131,7 @@ public class ContentNegotiationConfigurerTests { } @Test - public void setDefaultContentTypeStrategy() throws Exception { + void setDefaultContentTypeStrategy() throws Exception { this.configurer.defaultContentTypeStrategy(new FixedContentNegotiationStrategy(MediaType.APPLICATION_JSON)); ContentNegotiationManager manager = this.configurer.buildContentNegotiationManager(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/CorsRegistryTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/CorsRegistryTests.java index 3b2011e16da..9fb206e7cd7 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/CorsRegistryTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/CorsRegistryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,29 +32,29 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Sebastien Deleuze */ -public class CorsRegistryTests { +class CorsRegistryTests { private CorsRegistry registry; @BeforeEach - public void setUp() { + void setUp() { this.registry = new CorsRegistry(); } @Test - public void noMapping() { + void noMapping() { assertThat(this.registry.getCorsConfigurations()).isEmpty(); } @Test - public void multipleMappings() { + void multipleMappings() { this.registry.addMapping("/foo"); this.registry.addMapping("/bar"); assertThat(this.registry.getCorsConfigurations()).hasSize(2); } @Test - public void customizedMapping() { + void customizedMapping() { this.registry.addMapping("/foo").allowedOrigins("https://domain2.com", "https://domain2.com") .allowedMethods("DELETE").allowCredentials(true).allowPrivateNetwork(true) .allowedHeaders("header1", "header2").exposedHeaders("header3", "header4").maxAge(3600); @@ -71,7 +71,7 @@ public class CorsRegistryTests { } @Test - public void allowCredentials() { + void allowCredentials() { this.registry.addMapping("/foo").allowCredentials(true); CorsConfiguration config = this.registry.getCorsConfigurations().get("/foo"); assertThat(config.getAllowedOrigins()) diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurerTests.java index 986fc067ada..51fd7fbb4e0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class DefaultServletHandlerConfigurerTests { +class DefaultServletHandlerConfigurerTests { private DefaultServletHandlerConfigurer configurer; @@ -46,7 +46,7 @@ public class DefaultServletHandlerConfigurerTests { @BeforeEach - public void setup() { + void setup() { response = new MockHttpServletResponse(); servletContext = new DispatchingMockServletContext(); configurer = new DefaultServletHandlerConfigurer(servletContext); @@ -54,12 +54,12 @@ public class DefaultServletHandlerConfigurerTests { @Test - public void notEnabled() { + void notEnabled() { assertThat(configurer.buildHandlerMapping()).isNull(); } @Test - public void enable() throws Exception { + void enable() throws Exception { configurer.enable(); SimpleUrlHandlerMapping mapping = configurer.buildHandlerMapping(); HttpRequestHandler handler = (DefaultServletHttpRequestHandler) mapping.getUrlMap().get("/**"); @@ -77,7 +77,7 @@ public class DefaultServletHandlerConfigurerTests { } @Test - public void enableWithServletName() throws Exception { + void enableWithServletName() throws Exception { configurer.enable("defaultServlet"); SimpleUrlHandlerMapping mapping = configurer.buildHandlerMapping(); HttpRequestHandler handler = (DefaultServletHttpRequestHandler) mapping.getUrlMap().get("/**"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationIntegrationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationIntegrationTests.java index f48a0242fa5..b485c5fac27 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationIntegrationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -43,12 +43,12 @@ import static org.mockito.Mockito.mock; * * @author Stephane Nicoll */ -public class DelegatingWebMvcConfigurationIntegrationTests { +class DelegatingWebMvcConfigurationIntegrationTests { private ConfigurableApplicationContext context; @AfterEach - public void closeContext() { + void closeContext() { if (this.context != null) { this.context.close(); } 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 44e38864cba..3958eae2d30 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -91,7 +91,7 @@ public class DelegatingWebMvcConfigurationTests { @Test - public void requestMappingHandlerAdapter() { + void requestMappingHandlerAdapter() { webMvcConfig.setConfigurers(Collections.singletonList(webMvcConfigurer)); RequestMappingHandlerAdapter adapter = this.webMvcConfig.requestMappingHandlerAdapter( this.webMvcConfig.mvcContentNegotiationManager(), @@ -119,7 +119,7 @@ public class DelegatingWebMvcConfigurationTests { } @Test - public void configureMessageConverters() { + void configureMessageConverters() { HttpMessageConverter customConverter = mock(); StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(); WebMvcConfigurer configurer = new WebMvcConfigurer() { @@ -146,7 +146,7 @@ public class DelegatingWebMvcConfigurationTests { } @Test - public void getCustomValidator() { + void getCustomValidator() { given(webMvcConfigurer.getValidator()).willReturn(new LocalValidatorFactoryBean()); webMvcConfig.setConfigurers(Collections.singletonList(webMvcConfigurer)); @@ -156,7 +156,7 @@ public class DelegatingWebMvcConfigurationTests { } @Test - public void getCustomMessageCodesResolver() { + void getCustomMessageCodesResolver() { given(webMvcConfigurer.getMessageCodesResolver()).willReturn(new DefaultMessageCodesResolver()); webMvcConfig.setConfigurers(Collections.singletonList(webMvcConfigurer)); @@ -166,7 +166,7 @@ public class DelegatingWebMvcConfigurationTests { } @Test - public void handlerExceptionResolver() { + void handlerExceptionResolver() { webMvcConfig.setConfigurers(Collections.singletonList(webMvcConfigurer)); webMvcConfig.handlerExceptionResolver(webMvcConfig.mvcContentNegotiationManager()); @@ -185,7 +185,7 @@ public class DelegatingWebMvcConfigurationTests { } @Test - public void configureExceptionResolvers() { + void configureExceptionResolvers() { WebMvcConfigurer configurer = new WebMvcConfigurer() { @Override public void configureHandlerExceptionResolvers(List resolvers) { @@ -272,7 +272,7 @@ public class DelegatingWebMvcConfigurationTests { } @Test - public void configurePathPatternParser() { + void configurePathPatternParser() { PathPatternParser patternParser = new PathPatternParser(); PathMatcher pathMatcher = mock(); UrlPathHelper pathHelper = mock(); 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 9276161f25e..6846b84ec0f 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-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -69,21 +69,21 @@ public class InterceptorRegistryTests { @BeforeEach - public void setUp() { + void setUp() { this.registry = new InterceptorRegistry(); this.webInterceptor1 = new TestWebRequestInterceptor(); this.webInterceptor2 = new TestWebRequestInterceptor(); } @Test - public void addInterceptor() { + void addInterceptor() { this.registry.addInterceptor(this.interceptor1); List interceptors = getInterceptorsForPath(null); - assertThat(interceptors).isEqualTo(Arrays.asList(this.interceptor1)); + assertThat(interceptors).isEqualTo(List.of(this.interceptor1)); } @Test - public void addTwoInterceptors() { + void addTwoInterceptors() { this.registry.addInterceptor(this.interceptor1); this.registry.addInterceptor(this.interceptor2); List interceptors = getInterceptorsForPath(null); @@ -91,17 +91,17 @@ public class InterceptorRegistryTests { } @Test - public void addInterceptorsWithUrlPatterns() { + void addInterceptorsWithUrlPatterns() { this.registry.addInterceptor(this.interceptor1).addPathPatterns("/path1/**").excludePathPatterns("/path1/secret"); this.registry.addInterceptor(this.interceptor2).addPathPatterns("/path2"); - assertThat(getInterceptorsForPath("/path1/test")).isEqualTo(Arrays.asList(this.interceptor1)); - assertThat(getInterceptorsForPath("/path2")).isEqualTo(Arrays.asList(this.interceptor2)); - assertThat(getInterceptorsForPath("/path1/secret")).isEqualTo(Collections.emptyList()); + assertThat(getInterceptorsForPath("/path1/test")).containsExactly(this.interceptor1); + assertThat(getInterceptorsForPath("/path2")).containsExactly(this.interceptor2); + assertThat(getInterceptorsForPath("/path1/secret")).isEmpty(); } @Test - public void addWebRequestInterceptor() throws Exception { + void addWebRequestInterceptor() throws Exception { this.registry.addWebRequestInterceptor(this.webInterceptor1); List interceptors = getInterceptorsForPath(null); @@ -110,7 +110,7 @@ public class InterceptorRegistryTests { } @Test - public void addWebRequestInterceptors() throws Exception { + void addWebRequestInterceptors() throws Exception { this.registry.addWebRequestInterceptor(this.webInterceptor1); this.registry.addWebRequestInterceptor(this.webInterceptor2); List interceptors = getInterceptorsForPath(null); @@ -121,7 +121,7 @@ public class InterceptorRegistryTests { } @Test - public void addInterceptorsWithCustomPathMatcher() { + void addInterceptorsWithCustomPathMatcher() { PathMatcher pathMatcher = mock(); this.registry.addInterceptor(interceptor1).addPathPatterns("/path1/**").pathMatcher(pathMatcher); @@ -130,7 +130,7 @@ public class InterceptorRegistryTests { } @Test - public void addWebRequestInterceptorsWithUrlPatterns() throws Exception { + void addWebRequestInterceptorsWithUrlPatterns() throws Exception { this.registry.addWebRequestInterceptor(this.webInterceptor1).addPathPatterns("/path1"); this.registry.addWebRequestInterceptor(this.webInterceptor2).addPathPatterns("/path2"); @@ -154,7 +154,7 @@ public class InterceptorRegistryTests { } @Test - public void orderedInterceptors() { + void orderedInterceptors() { this.registry.addInterceptor(this.interceptor1).order(Ordered.LOWEST_PRECEDENCE); this.registry.addInterceptor(this.interceptor2).order(Ordered.HIGHEST_PRECEDENCE); @@ -166,7 +166,7 @@ public class InterceptorRegistryTests { } @Test - public void nonOrderedInterceptors() { + void nonOrderedInterceptors() { this.registry.addInterceptor(this.interceptor1).order(0); this.registry.addInterceptor(this.interceptor2).order(0); @@ -212,16 +212,16 @@ public class InterceptorRegistryTests { private boolean preHandleInvoked = false; @Override - public void preHandle(WebRequest request) throws Exception { + public void preHandle(WebRequest request) { preHandleInvoked = true; } @Override - public void postHandle(WebRequest request, @Nullable ModelMap model) throws Exception { + public void postHandle(WebRequest request, @Nullable ModelMap model) { } @Override - public void afterCompletion(WebRequest request, @Nullable Exception ex) throws Exception { + public void afterCompletion(WebRequest request, @Nullable Exception ex) { } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistryTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistryTests.java index 01713077d51..e7544f6a838 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistryTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistryTests.java @@ -53,7 +53,7 @@ import static org.mockito.Mockito.mock; * * @author Rossen Stoyanchev */ -public class ResourceHandlerRegistryTests { +class ResourceHandlerRegistryTests { private ResourceHandlerRegistry registry; @@ -63,7 +63,7 @@ public class ResourceHandlerRegistryTests { @BeforeEach - public void setup() { + void setup() { GenericWebApplicationContext appContext = new GenericWebApplicationContext(); appContext.refresh(); @@ -82,13 +82,13 @@ public class ResourceHandlerRegistryTests { @Test - public void noResourceHandlers() { + void noResourceHandlers() { this.registry = new ResourceHandlerRegistry(new GenericWebApplicationContext(), new MockServletContext()); assertThat(this.registry.getHandlerMapping()).isNull(); } @Test - public void mapPathToLocation() throws Exception { + void mapPathToLocation() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "/testStylesheet.css"); @@ -100,7 +100,7 @@ public class ResourceHandlerRegistryTests { } @Test - public void cachePeriod() { + void cachePeriod() { assertThat(getHandler("/resources/**").getCacheSeconds()).isEqualTo(-1); this.registration.setCachePeriod(0); @@ -108,7 +108,7 @@ public class ResourceHandlerRegistryTests { } @Test - public void cacheControl() { + void cacheControl() { assertThat(getHandler("/resources/**").getCacheControl()).isNull(); this.registration.setCacheControl(CacheControl.noCache().cachePrivate()); @@ -117,7 +117,7 @@ public class ResourceHandlerRegistryTests { } @Test - public void order() { + void order() { assertThat(registry.getHandlerMapping().getOrder()).isEqualTo(Integer.MAX_VALUE -1); registry.setOrder(0); @@ -125,13 +125,13 @@ public class ResourceHandlerRegistryTests { } @Test - public void hasMappingForPattern() { + void hasMappingForPattern() { assertThat(this.registry.hasMappingForPattern("/resources/**")).isTrue(); assertThat(this.registry.hasMappingForPattern("/whatever")).isFalse(); } @Test - public void resourceChain() { + void resourceChain() { ResourceResolver mockResolver = mock(); ResourceTransformer mockTransformer = mock(); this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer); @@ -153,7 +153,7 @@ public class ResourceHandlerRegistryTests { } @Test - public void resourceChainWithoutCaching() { + void resourceChainWithoutCaching() { this.registration.resourceChain(false); ResourceHttpRequestHandler handler = getHandler("/resources/**"); @@ -167,7 +167,7 @@ public class ResourceHandlerRegistryTests { } @Test - public void resourceChainWithVersionResolver() { + void resourceChainWithVersionResolver() { VersionResourceResolver versionResolver = new VersionResourceResolver() .addFixedVersionStrategy("fixed", "/**/*.js") .addContentVersionStrategy("/**"); @@ -189,7 +189,7 @@ public class ResourceHandlerRegistryTests { } @Test - public void resourceChainWithOverrides() { + void resourceChainWithOverrides() { CachingResourceResolver cachingResolver = mock(); VersionResourceResolver versionResolver = mock(); WebJarsResourceResolver webjarsResolver = mock(); @@ -208,20 +208,15 @@ public class ResourceHandlerRegistryTests { ResourceHttpRequestHandler handler = getHandler("/resources/**"); List resolvers = handler.getResourceResolvers(); - assertThat(resolvers).hasSize(4); - assertThat(resolvers).element(0).isSameAs(cachingResolver); - assertThat(resolvers).element(1).isSameAs(versionResolver); - assertThat(resolvers).element(2).isSameAs(webjarsResolver); - assertThat(resolvers).element(3).isSameAs(pathResourceResolver); + assertThat(resolvers).containsExactly( + cachingResolver, versionResolver, webjarsResolver, pathResourceResolver); List transformers = handler.getResourceTransformers(); - assertThat(transformers).hasSize(2); - assertThat(transformers).element(0).isSameAs(cachingTransformer); - assertThat(transformers).element(1).isSameAs(cssLinkTransformer); + assertThat(transformers).containsExactly(cachingTransformer, cssLinkTransformer); } @Test - public void urlResourceWithCharset() { + void urlResourceWithCharset() { this.registration.addResourceLocations("[charset=ISO-8859-1]file:///tmp"); this.registration.resourceChain(true); @@ -236,7 +231,7 @@ public class ResourceHandlerRegistryTests { } @Test - public void lastModifiedDisabled() { + void lastModifiedDisabled() { this.registration.setUseLastModified(false); ResourceHttpRequestHandler handler = getHandler("/resources/**"); assertThat(handler.isUseLastModified()).isFalse(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistryTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistryTests.java index 0509f8d030b..edc7d66cb9b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistryTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class ViewControllerRegistryTests { +class ViewControllerRegistryTests { private ViewControllerRegistry registry; @@ -47,7 +47,7 @@ public class ViewControllerRegistryTests { @BeforeEach - public void setup() { + void setup() { this.registry = new ViewControllerRegistry(new StaticApplicationContext()); this.request = new MockHttpServletRequest("GET", "/"); this.response = new MockHttpServletResponse(); @@ -55,12 +55,12 @@ public class ViewControllerRegistryTests { @Test - public void noViewControllers() { + void noViewControllers() { assertThat(this.registry.buildHandlerMapping()).isNull(); } @Test - public void addViewController() { + void addViewController() { this.registry.addViewController("/path").setViewName("viewName"); ParameterizableViewController controller = getController("/path"); @@ -71,7 +71,7 @@ public class ViewControllerRegistryTests { } @Test - public void addViewControllerWithDefaultViewName() { + void addViewControllerWithDefaultViewName() { this.registry.addViewController("/path"); ParameterizableViewController controller = getController("/path"); @@ -82,7 +82,7 @@ public class ViewControllerRegistryTests { } @Test - public void addRedirectViewController() throws Exception { + void addRedirectViewController() throws Exception { this.registry.addRedirectViewController("/path", "/redirectTo"); RedirectView redirectView = getRedirectView("/path"); this.request.setQueryString("a=b"); @@ -95,7 +95,7 @@ public class ViewControllerRegistryTests { } @Test - public void addRedirectViewControllerWithCustomSettings() throws Exception { + void addRedirectViewControllerWithCustomSettings() throws Exception { this.registry.addRedirectViewController("/path", "/redirectTo") .setContextRelative(false) .setKeepQueryParams(true) @@ -112,7 +112,7 @@ public class ViewControllerRegistryTests { } @Test - public void addStatusController() { + void addStatusController() { this.registry.addStatusController("/path", HttpStatus.NOT_FOUND); ParameterizableViewController controller = getController("/path"); @@ -123,7 +123,7 @@ public class ViewControllerRegistryTests { } @Test - public void order() { + void order() { this.registry.addViewController("/path"); SimpleUrlHandlerMapping handlerMapping = this.registry.buildHandlerMapping(); assertThat(handlerMapping.getOrder()).isEqualTo(1); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java index c01537426e8..41ffd90c591 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -46,29 +46,29 @@ import static org.assertj.core.api.Assertions.assertThatRuntimeException; * @author Rossen Stoyanchev * @since 4.1 */ -public class ViewResolutionIntegrationTests { +class ViewResolutionIntegrationTests { @Test - public void freemarker() throws Exception { + void freemarker() throws Exception { MockHttpServletResponse response = runTest(FreeMarkerWebConfig.class); assertThat(response.getContentAsString()).isEqualTo("Hello World!"); } @Test - public void groovyMarkup() throws Exception { + void groovyMarkup() throws Exception { MockHttpServletResponse response = runTest(GroovyMarkupWebConfig.class); assertThat(response.getContentAsString()).isEqualTo("Hello World!"); } @Test - public void freemarkerInvalidConfig() throws Exception { + void freemarkerInvalidConfig() { assertThatRuntimeException() .isThrownBy(() -> runTest(InvalidFreeMarkerWebConfig.class)) .withMessageContaining("In addition to a FreeMarker view resolver "); } @Test - public void groovyMarkupInvalidConfig() throws Exception { + void groovyMarkupInvalidConfig() { assertThatRuntimeException() .isThrownBy(() -> runTest(InvalidGroovyMarkupWebConfig.class)) .withMessageContaining("In addition to a Groovy markup view resolver "); @@ -77,7 +77,7 @@ public class ViewResolutionIntegrationTests { // SPR-12013 @Test - public void existingViewResolver() throws Exception { + void existingViewResolver() throws Exception { MockHttpServletResponse response = runTest(ExistingViewResolverConfig.class); assertThat(response.getContentAsString()).isEqualTo("Hello World!"); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistryTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistryTests.java index af47e9c81be..9b7f7e51d6d 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistryTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -46,13 +46,13 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sebastien Deleuze * @author Rossen Stoyanchev */ -public class ViewResolverRegistryTests { +class ViewResolverRegistryTests { private ViewResolverRegistry registry; @BeforeEach - public void setup() { + void setup() { StaticWebApplicationContext context = new StaticWebApplicationContext(); context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class); context.registerSingleton("groovyMarkupConfigurer", GroovyMarkupConfigurer.class); @@ -63,63 +63,63 @@ public class ViewResolverRegistryTests { @Test - public void order() { + void order() { assertThat(this.registry.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE); this.registry.enableContentNegotiation(); assertThat(this.registry.getOrder()).isEqualTo(Ordered.HIGHEST_PRECEDENCE); } @Test - public void hasRegistrations() { + void hasRegistrations() { assertThat(this.registry.hasRegistrations()).isFalse(); this.registry.freeMarker(); assertThat(this.registry.hasRegistrations()).isTrue(); } @Test - public void hasRegistrationsWhenContentNegotiationEnabled() { + void hasRegistrationsWhenContentNegotiationEnabled() { assertThat(this.registry.hasRegistrations()).isFalse(); this.registry.enableContentNegotiation(); assertThat(this.registry.hasRegistrations()).isTrue(); } @Test - public void noResolvers() { + void noResolvers() { assertThat(this.registry.getViewResolvers()).isNotNull(); assertThat(this.registry.getViewResolvers()).isEmpty(); assertThat(this.registry.hasRegistrations()).isFalse(); } @Test - public void customViewResolver() { + void customViewResolver() { InternalResourceViewResolver viewResolver = new InternalResourceViewResolver("/", ".jsp"); this.registry.viewResolver(viewResolver); assertThat(this.registry.getViewResolvers()).element(0).isSameAs(viewResolver); } @Test - public void beanName() { + void beanName() { this.registry.beanName(); assertThat(this.registry.getViewResolvers()).hasSize(1); assertThat(registry.getViewResolvers().get(0).getClass()).isEqualTo(BeanNameViewResolver.class); } @Test - public void jspDefaultValues() { + void jspDefaultValues() { this.registry.jsp(); InternalResourceViewResolver resolver = checkAndGetResolver(InternalResourceViewResolver.class); checkPropertyValues(resolver, "prefix", "/WEB-INF/", "suffix", ".jsp"); } @Test - public void jsp() { + void jsp() { this.registry.jsp("/", ".jsp"); InternalResourceViewResolver resolver = checkAndGetResolver(InternalResourceViewResolver.class); checkPropertyValues(resolver, "prefix", "/", "suffix", ".jsp"); } @Test - public void jspMultipleResolvers() { + void jspMultipleResolvers() { this.registry.jsp().viewNames("view1", "view2"); this.registry.jsp().viewNames("view3", "view4"); assertThat(this.registry.getViewResolvers()).isNotNull(); @@ -129,63 +129,63 @@ public class ViewResolverRegistryTests { } @Test - public void freeMarker() { + void freeMarker() { this.registry.freeMarker().prefix("/").suffix(".fmt").cache(false); FreeMarkerViewResolver resolver = checkAndGetResolver(FreeMarkerViewResolver.class); checkPropertyValues(resolver, "prefix", "/", "suffix", ".fmt", "cacheLimit", 0); } @Test - public void freeMarkerDefaultValues() { + void freeMarkerDefaultValues() { this.registry.freeMarker(); FreeMarkerViewResolver resolver = checkAndGetResolver(FreeMarkerViewResolver.class); checkPropertyValues(resolver, "prefix", "", "suffix", ".ftl"); } @Test - public void groovyMarkup() { + void groovyMarkup() { this.registry.groovy().prefix("/").suffix(".groovy").cache(true); GroovyMarkupViewResolver resolver = checkAndGetResolver(GroovyMarkupViewResolver.class); checkPropertyValues(resolver, "prefix", "/", "suffix", ".groovy", "cacheLimit", 1024); } @Test - public void groovyMarkupDefaultValues() { + void groovyMarkupDefaultValues() { this.registry.groovy(); GroovyMarkupViewResolver resolver = checkAndGetResolver(GroovyMarkupViewResolver.class); checkPropertyValues(resolver, "prefix", "", "suffix", ".tpl"); } @Test - public void scriptTemplate() { + void scriptTemplate() { this.registry.scriptTemplate().prefix("/").suffix(".html").cache(true); ScriptTemplateViewResolver resolver = checkAndGetResolver(ScriptTemplateViewResolver.class); checkPropertyValues(resolver, "prefix", "/", "suffix", ".html", "cacheLimit", 1024); } @Test - public void scriptTemplateDefaultValues() { + void scriptTemplateDefaultValues() { this.registry.scriptTemplate(); ScriptTemplateViewResolver resolver = checkAndGetResolver(ScriptTemplateViewResolver.class); checkPropertyValues(resolver, "prefix", "", "suffix", ""); } @Test - public void contentNegotiation() { + void contentNegotiation() { MappingJackson2JsonView view = new MappingJackson2JsonView(); this.registry.enableContentNegotiation(view); ContentNegotiatingViewResolver resolver = checkAndGetResolver(ContentNegotiatingViewResolver.class); - assertThat(resolver.getDefaultViews()).isEqualTo(Arrays.asList(view)); + assertThat(resolver.getDefaultViews()).containsExactly(view); assertThat(this.registry.getOrder()).isEqualTo(Ordered.HIGHEST_PRECEDENCE); } @Test - public void contentNegotiationAddsDefaultViewRegistrations() { + void contentNegotiationAddsDefaultViewRegistrations() { MappingJackson2JsonView view1 = new MappingJackson2JsonView(); this.registry.enableContentNegotiation(view1); ContentNegotiatingViewResolver resolver1 = checkAndGetResolver(ContentNegotiatingViewResolver.class); - assertThat(resolver1.getDefaultViews()).isEqualTo(Arrays.asList(view1)); + assertThat(resolver1.getDefaultViews()).containsExactly(view1); MarshallingView view2 = new MarshallingView(); this.registry.enableContentNegotiation(view2); 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 2428c727da8..13738ff588f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -96,7 +96,7 @@ import static org.springframework.http.MediaType.APPLICATION_XML; /** * A test fixture with a subclass of {@link WebMvcConfigurationSupport} that also * implements the various {@link WebMvcConfigurer} extension points. - * + *

* The former doesn't implement the latter but the two must have compatible * callback method signatures to support moving from simple to advanced * configuration -- i.e. dropping @EnableWebMvc + WebMvcConfigurer and extending @@ -105,7 +105,7 @@ import static org.springframework.http.MediaType.APPLICATION_XML; * @author Rossen Stoyanchev * @author Sebastien Deleuze */ -public class WebMvcConfigurationSupportExtensionTests { +class WebMvcConfigurationSupportExtensionTests { private TestWebMvcConfigurationSupport config; @@ -113,7 +113,7 @@ public class WebMvcConfigurationSupportExtensionTests { @BeforeEach - public void setUp() { + void setUp() { this.context = new StaticWebApplicationContext(); this.context.setServletContext(new MockServletContext(new FileSystemResourceLoader())); this.context.registerSingleton("controller", TestController.class); @@ -125,7 +125,7 @@ public class WebMvcConfigurationSupportExtensionTests { } @Test - public void handlerMappings() throws Exception { + void handlerMappings() throws Exception { RequestMappingHandlerMapping rmHandlerMapping = this.config.requestMappingHandlerMapping( this.config.mvcContentNegotiationManager(), this.config.mvcConversionService(), this.config.mvcResourceUrlProvider()); @@ -199,7 +199,7 @@ public class WebMvcConfigurationSupportExtensionTests { @SuppressWarnings("unchecked") @Test - public void requestMappingHandlerAdapter() { + void requestMappingHandlerAdapter() { RequestMappingHandlerAdapter adapter = this.config.requestMappingHandlerAdapter( this.config.mvcContentNegotiationManager(), this.config.mvcConversionService(), this.config.mvcValidator()); @@ -245,7 +245,7 @@ public class WebMvcConfigurationSupportExtensionTests { } @Test - public void webBindingInitializer() throws Exception { + void webBindingInitializer() { RequestMappingHandlerAdapter adapter = this.config.requestMappingHandlerAdapter( this.config.mvcContentNegotiationManager(), this.config.mvcConversionService(), this.config.mvcValidator()); @@ -295,7 +295,7 @@ public class WebMvcConfigurationSupportExtensionTests { } @Test - public void exceptionResolvers() throws Exception { + void exceptionResolvers() { List resolvers = ((HandlerExceptionResolverComposite) this.config.handlerExceptionResolver(null)).getExceptionResolvers(); @@ -306,7 +306,7 @@ public class WebMvcConfigurationSupportExtensionTests { @SuppressWarnings("unchecked") @Test - public void viewResolvers() throws Exception { + void viewResolvers() { ViewResolverComposite viewResolver = (ViewResolverComposite) this.config.mvcViewResolver( this.config.mvcContentNegotiationManager()); assertThat(viewResolver.getOrder()).isEqualTo(Ordered.HIGHEST_PRECEDENCE); @@ -333,10 +333,10 @@ public class WebMvcConfigurationSupportExtensionTests { } @Test - public void crossOrigin() { + void crossOrigin() { Map configs = this.config.getCorsConfigurations(); assertThat(configs).hasSize(1); - assertThat(configs.get("/resources/**").getAllowedOrigins()).element(0).isEqualTo("*"); + assertThat(configs.get("/resources/**").getAllowedOrigins()).containsExactly("*"); } @@ -432,7 +432,6 @@ public class WebMvcConfigurationSupportExtensionTests { registry.addInterceptor(new LocaleChangeInterceptor()); } - @SuppressWarnings("serial") @Override public MessageCodesResolver getMessageCodesResolver() { return new DefaultMessageCodesResolver() { @@ -473,10 +472,10 @@ public class WebMvcConfigurationSupportExtensionTests { } - private class TestPathHelper extends UrlPathHelper { + private static class TestPathHelper extends UrlPathHelper { } - private class TestPathMatcher extends AntPathMatcher { + private static class TestPathMatcher extends AntPathMatcher { } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportTests.java index b6e48b3de2a..899ad38ea28 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -111,10 +111,10 @@ import static org.springframework.web.servlet.DispatcherServlet.THEME_RESOLVER_B * @author Sam Brannen * @author Marten Deinum */ -public class WebMvcConfigurationSupportTests { +class WebMvcConfigurationSupportTests { @Test - public void requestMappingHandlerMapping() throws Exception { + void requestMappingHandlerMapping() throws Exception { ApplicationContext context = initContext(WebConfig.class, ScopedController.class, ScopedProxyController.class); RequestMappingHandlerMapping handlerMapping = context.getBean(RequestMappingHandlerMapping.class); assertThat(handlerMapping.getOrder()).isEqualTo(0); @@ -133,7 +133,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void emptyHandlerMappings() { + void emptyHandlerMappings() { ApplicationContext context = initContext(WebConfig.class); Map handlerMappings = context.getBeansOfType(HandlerMapping.class); @@ -152,7 +152,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void beanNameHandlerMapping() throws Exception { + void beanNameHandlerMapping() throws Exception { ApplicationContext context = initContext(WebConfig.class); BeanNameUrlHandlerMapping handlerMapping = context.getBean(BeanNameUrlHandlerMapping.class); assertThat(handlerMapping.getOrder()).isEqualTo(2); @@ -169,7 +169,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void requestMappingHandlerAdapter() { + void requestMappingHandlerAdapter() { ApplicationContext context = initContext(WebConfig.class); RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class); List> converters = adapter.getMessageConverters(); @@ -209,7 +209,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void uriComponentsContributor() { + void uriComponentsContributor() { ApplicationContext context = initContext(WebConfig.class); CompositeUriComponentsContributor uriComponentsContributor = context.getBean( MvcUriComponentsBuilder.MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME, @@ -254,7 +254,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void customArgumentResolvers() { + void customArgumentResolvers() { ApplicationContext context = initContext(CustomArgumentResolverConfig.class); RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class); HandlerExceptionResolverComposite composite = context.getBean(HandlerExceptionResolverComposite.class); @@ -280,7 +280,7 @@ public class WebMvcConfigurationSupportTests { @Test - public void mvcViewResolver() { + void mvcViewResolver() { ApplicationContext context = initContext(WebConfig.class); ViewResolverComposite resolver = context.getBean("mvcViewResolver", ViewResolverComposite.class); @@ -291,7 +291,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void mvcViewResolverWithExistingResolver() throws Exception { + void mvcViewResolverWithExistingResolver() throws Exception { ApplicationContext context = initContext(WebConfig.class, ViewResolverConfig.class); ViewResolverComposite resolver = context.getBean("mvcViewResolver", ViewResolverComposite.class); @@ -302,7 +302,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void mvcViewResolverWithOrderSet() { + void mvcViewResolverWithOrderSet() { ApplicationContext context = initContext(CustomViewResolverOrderConfig.class); ViewResolverComposite resolver = context.getBean("mvcViewResolver", ViewResolverComposite.class); @@ -313,7 +313,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void defaultPathMatchConfiguration() { + void defaultPathMatchConfiguration() { ApplicationContext context = initContext(WebConfig.class); UrlPathHelper urlPathHelper = context.getBean(UrlPathHelper.class); PathMatcher pathMatcher = context.getBean(PathMatcher.class); @@ -324,7 +324,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void defaultLocaleResolverConfiguration() { + void defaultLocaleResolverConfiguration() { ApplicationContext context = initContext(WebConfig.class); LocaleResolver localeResolver = context.getBean(LOCALE_RESOLVER_BEAN_NAME, LocaleResolver.class); @@ -344,7 +344,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void defaultFlashMapManagerConfiguration() { + void defaultFlashMapManagerConfiguration() { ApplicationContext context = initContext(WebConfig.class); FlashMapManager flashMapManager = context.getBean(FLASH_MAP_MANAGER_BEAN_NAME, FlashMapManager.class); @@ -353,7 +353,7 @@ public class WebMvcConfigurationSupportTests { } @Test - public void defaultRequestToViewNameConfiguration() throws Exception { + void defaultRequestToViewNameConfiguration() { ApplicationContext context = initContext(WebConfig.class); RequestToViewNameTranslator requestToViewNameTranslator; requestToViewNameTranslator = context.getBean(REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME, diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/AttributesTestVisitor.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/AttributesTestVisitor.java index 0cf0e64db7e..0e438a66c3c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/AttributesTestVisitor.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/AttributesTestVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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 java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.function.Function; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.springframework.core.io.Resource; @@ -34,13 +33,13 @@ import org.springframework.lang.Nullable; */ class AttributesTestVisitor implements RouterFunctions.Visitor { - private Deque> nestedAttributes = new LinkedList<>(); + private final Deque> nestedAttributes = new LinkedList<>(); + + private final List>> routerFunctionsAttributes = new LinkedList<>(); @Nullable private Map attributes; - private List>> routerFunctionsAttributes = new LinkedList<>(); - private int visitCount; public List>> routerFunctionsAttributes() { @@ -66,7 +65,7 @@ class AttributesTestVisitor implements RouterFunctions.Visitor { public void route(RequestPredicate predicate, HandlerFunction handlerFunction) { Stream> current = Optional.ofNullable(attributes).stream(); Stream> nested = nestedAttributes.stream().filter(Objects::nonNull); - routerFunctionsAttributes.add(Stream.concat(current, nested).collect(Collectors.toUnmodifiableList())); + routerFunctionsAttributes.add(Stream.concat(current, nested).toList()); attributes = null; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultEntityResponseBuilderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultEntityResponseBuilderTests.java index 8ccecc9a54a..08cf765c11c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultEntityResponseBuilderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultEntityResponseBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -19,7 +19,6 @@ package org.springframework.web.servlet.function; import java.io.IOException; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; import java.util.Set; @@ -47,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ class DefaultEntityResponseBuilderTests { - static final ServerResponse.Context EMPTY_CONTEXT = () -> Collections.emptyList(); + static final ServerResponse.Context EMPTY_CONTEXT = Collections::emptyList; @Test void fromObject() { @@ -195,7 +194,7 @@ class DefaultEntityResponseBuilderTests { @Test void notModifiedLastModified() throws ServletException, IOException { ZonedDateTime now = ZonedDateTime.now(); - ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES); + ZonedDateTime oneMinuteBeforeNow = now.minusMinutes(1); EntityResponse entityResponse = EntityResponse.fromObject("bar") .lastModified(oneMinuteBeforeNow) diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultRenderingResponseTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultRenderingResponseTests.java index 476ac65e50b..5472016cb48 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultRenderingResponseTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultRenderingResponseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -18,7 +18,6 @@ package org.springframework.web.servlet.function; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.Map; @@ -38,12 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Arjen Poutsma */ -public class DefaultRenderingResponseTests { +class DefaultRenderingResponseTests { - static final ServerResponse.Context EMPTY_CONTEXT = () -> Collections.emptyList(); + static final ServerResponse.Context EMPTY_CONTEXT = Collections::emptyList; @Test - public void create() throws Exception { + void create() throws Exception { String name = "foo"; RenderingResponse result = RenderingResponse.create(name).build(); @@ -55,7 +54,7 @@ public class DefaultRenderingResponseTests { } @Test - public void status() throws Exception { + void status() throws Exception { HttpStatus status = HttpStatus.I_AM_A_TEAPOT; RenderingResponse result = RenderingResponse.create("foo").status(status).build(); @@ -67,7 +66,7 @@ public class DefaultRenderingResponseTests { } @Test - public void headers() throws Exception { + void headers() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.set("foo", "bar"); RenderingResponse result = RenderingResponse.create("foo") @@ -83,7 +82,7 @@ public class DefaultRenderingResponseTests { } @Test - public void modelAttribute() throws Exception { + void modelAttribute() throws Exception { RenderingResponse result = RenderingResponse.create("foo") .modelAttribute("foo", "bar").build(); @@ -97,7 +96,7 @@ public class DefaultRenderingResponseTests { @Test - public void modelAttributeConventions() throws Exception { + void modelAttributeConventions() throws Exception { RenderingResponse result = RenderingResponse.create("foo") .modelAttribute("bar").build(); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -108,7 +107,7 @@ public class DefaultRenderingResponseTests { } @Test - public void modelAttributes() throws Exception { + void modelAttributes() throws Exception { Map model = Collections.singletonMap("foo", "bar"); RenderingResponse result = RenderingResponse.create("foo") .modelAttributes(model).build(); @@ -120,7 +119,7 @@ public class DefaultRenderingResponseTests { } @Test - public void modelAttributesConventions() throws Exception { + void modelAttributesConventions() throws Exception { RenderingResponse result = RenderingResponse.create("foo") .modelAttributes("bar").build(); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -131,7 +130,7 @@ public class DefaultRenderingResponseTests { } @Test - public void cookies() throws Exception { + void cookies() throws Exception { MultiValueMap newCookies = new LinkedMultiValueMap<>(); newCookies.add("name", new Cookie("name", "value")); RenderingResponse result = @@ -146,7 +145,7 @@ public class DefaultRenderingResponseTests { } @Test - public void notModifiedEtag() throws Exception { + void notModifiedEtag() throws Exception { String etag = "\"foo\""; RenderingResponse result = RenderingResponse.create("bar") .header(HttpHeaders.ETAG, etag) @@ -163,9 +162,9 @@ public class DefaultRenderingResponseTests { @Test - public void notModifiedLastModified() throws Exception { + void notModifiedLastModified() throws Exception { ZonedDateTime now = ZonedDateTime.now(); - ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES); + ZonedDateTime oneMinuteBeforeNow = now.minusMinutes(1); RenderingResponse result = RenderingResponse.create("bar") .header(HttpHeaders.LAST_MODIFIED, DateTimeFormatter.RFC_1123_DATE_TIME.format(oneMinuteBeforeNow)) 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 9b933c52fda..1690193cf19 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -266,13 +266,11 @@ class DefaultServerRequestTests { List.of(new MappingJackson2HttpMessageConverter())); List result = request.body(new ParameterizedTypeReference<>() {}); - assertThat(result).hasSize(2); - assertThat(result).element(0).isEqualTo("foo"); - assertThat(result).element(1).isEqualTo("bar"); + assertThat(result).containsExactly("foo", "bar"); } @Test - void bodyUnacceptable() throws Exception { + void bodyUnacceptable() { MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true); servletRequest.setContentType(MediaType.TEXT_PLAIN_VALUE); servletRequest.setContent("foo".getBytes(UTF_8)); @@ -358,7 +356,7 @@ class DefaultServerRequestTests { } @Test - void bindError() throws BindException { + void bindError() { MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true); servletRequest.addParameter("foo", "FOO"); @@ -371,7 +369,7 @@ class DefaultServerRequestTests { @ParameterizedHttpMethodTest - void checkNotModifiedTimestamp(String method) throws Exception { + void checkNotModifiedTimestamp(String method) { MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest(method, "/", true); Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS); servletRequest.addHeader(HttpHeaders.IF_MODIFIED_SINCE, now.toEpochMilli()); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerResponseBuilderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerResponseBuilderTests.java index 335f7ece51b..a5e05a76d1c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerResponseBuilderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerResponseBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -19,7 +19,6 @@ package org.springframework.web.servlet.function; import java.net.URI; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -53,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ class DefaultServerResponseBuilderTests { - static final ServerResponse.Context EMPTY_CONTEXT = () -> Collections.emptyList(); + static final ServerResponse.Context EMPTY_CONTEXT = Collections::emptyList; @Test @SuppressWarnings("deprecation") @@ -257,7 +256,7 @@ class DefaultServerResponseBuilderTests { @Test void notModifiedLastModified() throws Exception { ZonedDateTime now = ZonedDateTime.now(); - ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES); + ZonedDateTime oneMinuteBeforeNow = now.minusMinutes(1); ServerResponse response = ServerResponse.ok() .lastModified(oneMinuteBeforeNow) diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RequestPredicatesTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RequestPredicatesTests.java index f030776ef90..4da80ab5e8a 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RequestPredicatesTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RequestPredicatesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -149,7 +149,7 @@ class RequestPredicatesTests { } @Test - public void pathWithContext() { + void pathWithContext() { RequestPredicate predicate = RequestPredicates.path("/p*"); ServerRequest request = initRequest("GET", "/context/path", servletRequest -> servletRequest.setContextPath("/context")); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/ResourceHandlerFunctionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/ResourceHandlerFunctionTests.java index a132b943acc..9c6d9320fda 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/ResourceHandlerFunctionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/ResourceHandlerFunctionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -46,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Arjen Poutsma */ -public class ResourceHandlerFunctionTests { +class ResourceHandlerFunctionTests { private final Resource resource = new ClassPathResource("response.txt", getClass()); @@ -57,7 +57,7 @@ public class ResourceHandlerFunctionTests { private ResourceHttpMessageConverter messageConverter; @BeforeEach - public void createContext() { + void createContext() { this.messageConverter = new ResourceHttpMessageConverter(); ResourceRegionHttpMessageConverter regionConverter = new ResourceRegionHttpMessageConverter(); this.context = () -> Arrays.asList(messageConverter, regionConverter); @@ -65,7 +65,7 @@ public class ResourceHandlerFunctionTests { @Test - public void get() throws IOException, ServletException { + void get() throws IOException, ServletException { MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true); ServerRequest request = new DefaultServerRequest(servletRequest, Collections.singletonList(messageConverter)); @@ -89,7 +89,7 @@ public class ResourceHandlerFunctionTests { } @Test - public void getRange() throws IOException, ServletException { + void getRange() throws IOException, ServletException { MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true); servletRequest.addHeader("Range", "bytes=0-5"); ServerRequest request = new DefaultServerRequest(servletRequest, Collections.singletonList(messageConverter)); @@ -118,7 +118,7 @@ public class ResourceHandlerFunctionTests { } @Test - public void getInvalidRange() throws IOException, ServletException { + void getInvalidRange() throws IOException, ServletException { MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true); servletRequest.addHeader("Range", "bytes=0-10, 0-10, 0-10, 0-10, 0-10, 0-10"); ServerRequest request = new DefaultServerRequest(servletRequest, Collections.singletonList(messageConverter)); @@ -144,7 +144,7 @@ public class ResourceHandlerFunctionTests { } @Test - public void head() throws IOException, ServletException { + void head() throws IOException, ServletException { MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("HEAD", "/", true); ServerRequest request = new DefaultServerRequest(servletRequest, Collections.singletonList(messageConverter)); @@ -168,7 +168,7 @@ public class ResourceHandlerFunctionTests { } @Test - public void options() throws ServletException, IOException { + void options() throws ServletException, IOException { MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("OPTIONS", "/", true); ServerRequest request = new DefaultServerRequest(servletRequest, Collections.singletonList(messageConverter)); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionBuilderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionBuilderTests.java index b2a50587fda..5e3c83baa15 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionBuilderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionBuilderTests.java @@ -121,7 +121,7 @@ class RouterFunctionBuilderTests { } @Test - public void resourcesCaching() { + void resourcesCaching() { Resource resource = new ClassPathResource("/org/springframework/web/servlet/function/"); assertThat(resource.exists()).isTrue(); @@ -204,7 +204,7 @@ class RouterFunctionBuilderTests { } @Test - public void multipleOnErrors() { + void multipleOnErrors() { RouterFunction route = RouterFunctions.route() .GET("/error", request -> { throw new IOException(); @@ -237,7 +237,7 @@ class RouterFunctionBuilderTests { } @Test - public void attributes() { + void attributes() { RouterFunction route = RouterFunctions.route() .GET("/atts/1", request -> ServerResponse.ok().build()) .withAttribute("foo", "bar") diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionTests.java index 3a0f2213565..baa3fd2e5a1 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -116,7 +116,7 @@ class RouterFunctionTests { @Test - public void attributes() { + void attributes() { RouterFunction route = RouterFunctions.route( GET("/atts/1"), request -> ServerResponse.ok().build()) .withAttribute("foo", "bar") diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionsTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionsTests.java index b98ba0ed72a..8e155251bc3 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionsTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/RouterFunctionsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -31,14 +31,14 @@ import static org.mockito.Mockito.mock; /** * @author Arjen Poutsma */ -public class RouterFunctionsTests { +class RouterFunctionsTests { private final ServerRequest request = new DefaultServerRequest( PathPatternsTestUtils.initRequest("GET", "", true), Collections.emptyList()); @Test - public void routeMatch() { + void routeMatch() { HandlerFunction handlerFunction = request -> ServerResponse.ok().build(); RequestPredicate requestPredicate = mock(); @@ -54,7 +54,7 @@ public class RouterFunctionsTests { } @Test - public void routeNoMatch() { + void routeNoMatch() { HandlerFunction handlerFunction = request -> ServerResponse.ok().build(); RequestPredicate requestPredicate = mock(); @@ -68,7 +68,7 @@ public class RouterFunctionsTests { } @Test - public void nestMatch() { + void nestMatch() { HandlerFunction handlerFunction = request -> ServerResponse.ok().build(); RouterFunction routerFunction = request -> Optional.of(handlerFunction); @@ -84,7 +84,7 @@ public class RouterFunctionsTests { } @Test - public void nestNoMatch() { + void nestNoMatch() { HandlerFunction handlerFunction = request -> ServerResponse.ok().build(); RouterFunction routerFunction = request -> Optional.of(handlerFunction); @@ -99,7 +99,7 @@ public class RouterFunctionsTests { } @Test - public void nestPathVariable() { + void nestPathVariable() { HandlerFunction handlerFunction = request -> ServerResponse.ok().build(); RequestPredicate requestPredicate = request -> request.pathVariable("foo").equals("bar"); RouterFunction nestedFunction = RouterFunctions.route(requestPredicate, handlerFunction); @@ -115,7 +115,7 @@ public class RouterFunctionsTests { } @Test - public void composedPathVariable() { + void composedPathVariable() { HandlerFunction handlerFunction = request -> ServerResponse.ok().build(); RequestPredicate requestPredicate = RequestPredicates.path("/{foo}").and( request -> request.pathVariable("foo").equals("bar")); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMappingTests.java index 9f957ad3c98..e3056633b8c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package org.springframework.web.servlet.handler; -import jakarta.servlet.ServletException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,13 +35,13 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Rod Johnson * @author Juergen Hoeller */ -public class BeanNameUrlHandlerMappingTests { +class BeanNameUrlHandlerMappingTests { private ConfigurableWebApplicationContext wac; @BeforeEach - public void setUp() throws Exception { + void setUp() { MockServletContext sc = new MockServletContext(""); wac = new XmlWebApplicationContext(); wac.setServletContext(sc); @@ -51,7 +50,7 @@ public class BeanNameUrlHandlerMappingTests { } @Test - public void requestsWithoutHandlers() throws Exception { + void requestsWithoutHandlers() throws Exception { HandlerMapping hm = (HandlerMapping) wac.getBean("handlerMapping"); MockHttpServletRequest req = new MockHttpServletRequest("GET", "/myapp/mypath/nonsense.html"); @@ -65,13 +64,13 @@ public class BeanNameUrlHandlerMappingTests { } @Test - public void requestsWithSubPaths() throws Exception { + void requestsWithSubPaths() throws Exception { HandlerMapping hm = (HandlerMapping) wac.getBean("handlerMapping"); doTestRequestsWithSubPaths(hm); } @Test - public void requestsWithSubPathsInParentContext() throws Exception { + void requestsWithSubPathsInParentContext() throws Exception { BeanNameUrlHandlerMapping hm = new BeanNameUrlHandlerMapping(); hm.setDetectHandlersInAncestorContexts(true); hm.setApplicationContext(new StaticApplicationContext(wac)); @@ -118,7 +117,7 @@ public class BeanNameUrlHandlerMappingTests { } @Test - public void requestsWithFullPaths() throws Exception { + void requestsWithFullPaths() throws Exception { UrlPathHelper pathHelper = new UrlPathHelper(); pathHelper.setAlwaysUseFullPath(true); @@ -156,7 +155,7 @@ public class BeanNameUrlHandlerMappingTests { } @Test - public void asteriskMatches() throws Exception { + void asteriskMatches() throws Exception { HandlerMapping hm = (HandlerMapping) wac.getBean("handlerMapping"); Object bean = wac.getBean("godCtrl"); @@ -174,7 +173,7 @@ public class BeanNameUrlHandlerMappingTests { } @Test - public void overlappingMappings() throws Exception { + void overlappingMappings() throws Exception { BeanNameUrlHandlerMapping hm = (BeanNameUrlHandlerMapping) wac.getBean("handlerMapping"); Object anotherHandler = new Object(); hm.registerHandler("/mypath/testaross*", anotherHandler); @@ -194,7 +193,7 @@ public class BeanNameUrlHandlerMappingTests { } @Test - public void doubleMappings() throws ServletException { + void doubleMappings() { BeanNameUrlHandlerMapping hm = (BeanNameUrlHandlerMapping) wac.getBean("handlerMapping"); assertThatIllegalStateException().isThrownBy(() -> hm.registerHandler("/mypath/welcome.html", new Object())); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingIntrospectorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingIntrospectorTests.java index 1049f904e15..7b573987478 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingIntrospectorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingIntrospectorTests.java @@ -71,7 +71,7 @@ import static org.springframework.web.servlet.HandlerMapping.BEST_MATCHING_PATTE * @author Rossen Stoyanchev * @since 4.3.1 */ -public class HandlerMappingIntrospectorTests { +class HandlerMappingIntrospectorTests { @Test void detectHandlerMappings() { 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 a17596bfc3d..75d7eca575f 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-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -68,7 +68,7 @@ public class HandlerMethodMappingTests { @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { this.mapping = new MyHandlerMethodMapping(); this.handler = new MyHandler(); this.method1 = handler.getClass().getMethod("handlerMethod1"); @@ -77,14 +77,14 @@ public class HandlerMethodMappingTests { @Test - public void registerDuplicates() { + void registerDuplicates() { this.mapping.registerMapping("foo", this.handler, this.method1); assertThatIllegalStateException().isThrownBy(() -> this.mapping.registerMapping("foo", this.handler, this.method2)); } @Test - public void directMatch() throws Exception { + void directMatch() throws Exception { this.mapping.registerMapping("/foo", this.handler, this.method1); this.mapping.registerMapping("/fo*", this.handler, this.method2); @@ -97,7 +97,7 @@ public class HandlerMethodMappingTests { } @Test - public void patternMatch() throws Exception { + void patternMatch() throws Exception { this.mapping.registerMapping("/fo*", this.handler, this.method1); this.mapping.registerMapping("/f*", this.handler, this.method2); @@ -108,7 +108,7 @@ public class HandlerMethodMappingTests { } @Test - public void ambiguousMatch() { + void ambiguousMatch() { this.mapping.registerMapping("/f?o", this.handler, this.method1); this.mapping.registerMapping("/fo?", this.handler, this.method2); @@ -163,7 +163,7 @@ public class HandlerMethodMappingTests { } @Test - public void abortInterceptorInPreFlightRequestWithCorsConfig() throws Exception { + void abortInterceptorInPreFlightRequestWithCorsConfig() throws Exception { this.mapping.registerMapping("/foo", this.handler, this.handler.getClass().getMethod("corsHandlerMethod")); MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/foo"); @@ -187,7 +187,7 @@ public class HandlerMethodMappingTests { } @Test - public void detectHandlerMethodsInAncestorContexts() { + void detectHandlerMethodsInAncestorContexts() { StaticApplicationContext cxt = new StaticApplicationContext(); cxt.registerSingleton("myHandler", MyHandler.class); @@ -206,7 +206,7 @@ public class HandlerMethodMappingTests { } @Test - public void registerMapping() { + void registerMapping() { String key1 = "/foo"; String key2 = "/foo*"; this.mapping.registerMapping(key1, this.handler, this.method1); @@ -215,9 +215,7 @@ public class HandlerMethodMappingTests { // Direct URL lookup List directUrlMatches = this.mapping.getMappingRegistry().getMappingsByDirectPath(key1); - assertThat(directUrlMatches).isNotNull(); - assertThat(directUrlMatches).hasSize(1); - assertThat(directUrlMatches).element(0).isEqualTo(key1); + assertThat(directUrlMatches).containsExactly(key1); // Mapping name lookup @@ -238,7 +236,7 @@ public class HandlerMethodMappingTests { } @Test - public void registerMappingWithSameMethodAndTwoHandlerInstances() { + void registerMappingWithSameMethodAndTwoHandlerInstances() { String key1 = "foo"; String key2 = "bar"; @@ -254,9 +252,7 @@ public class HandlerMethodMappingTests { // Direct URL lookup List directUrlMatches = this.mapping.getMappingRegistry().getMappingsByDirectPath(key1); - assertThat(directUrlMatches).isNotNull(); - assertThat(directUrlMatches).hasSize(1); - assertThat(directUrlMatches).element(0).isEqualTo(key1); + assertThat(directUrlMatches).containsExactly(key1); // Mapping name lookup @@ -269,7 +265,7 @@ public class HandlerMethodMappingTests { } @Test - public void unregisterMapping() throws Exception { + void unregisterMapping() throws Exception { String key = "foo"; HandlerMethod handlerMethod = new HandlerMethod(this.handler, this.method1); @@ -284,7 +280,7 @@ public class HandlerMethodMappingTests { } @Test - public void getCorsConfigWithBeanNameHandler() throws Exception { + void getCorsConfigWithBeanNameHandler() throws Exception { String key = "foo"; String beanName = "handler1"; @@ -300,9 +296,9 @@ public class HandlerMethodMappingTests { private static class MyHandlerMethodMapping extends AbstractHandlerMethodMapping { - private UrlPathHelper pathHelper = new UrlPathHelper(); + private final UrlPathHelper pathHelper = new UrlPathHelper(); - private PathMatcher pathMatcher = new AntPathMatcher(); + private final PathMatcher pathMatcher = new AntPathMatcher(); private final List matches = new ArrayList<>(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathMatchingUrlHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathMatchingUrlHandlerMappingTests.java index 0ec6fd054f6..6b42b3e4f24 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathMatchingUrlHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/PathMatchingUrlHandlerMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Alef Arendsen * @author Juergen Hoeller */ -public class PathMatchingUrlHandlerMappingTests { +class PathMatchingUrlHandlerMappingTests { @SuppressWarnings("unused") static Stream pathPatternsArguments() { @@ -67,15 +67,15 @@ public class PathMatchingUrlHandlerMappingTests { Object bean = wac.getBean("mainController"); MockHttpServletRequest req = new MockHttpServletRequest("GET", "/welcome.html"); - HandlerExecutionChain hec = getHandler(mapping, wac, req); + HandlerExecutionChain hec = getHandler(mapping, req); assertThat(hec.getHandler()).isSameAs(bean); req = new MockHttpServletRequest("GET", "/show.html"); - hec = getHandler(mapping, wac, req); + hec = getHandler(mapping, req); assertThat(hec.getHandler()).isSameAs(bean); req = new MockHttpServletRequest("GET", "/bookseats.html"); - hec = getHandler(mapping, wac, req); + hec = getHandler(mapping, req); assertThat(hec.getHandler()).isSameAs(bean); } @@ -89,153 +89,153 @@ public class PathMatchingUrlHandlerMappingTests { // testing some normal behavior MockHttpServletRequest request = new MockHttpServletRequest("GET", "/pathmatchingTest.html"); - HandlerExecutionChain chain = getHandler(mapping, wac, request); + HandlerExecutionChain chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); assertThat(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .isEqualTo("/pathmatchingTest.html"); // no match, no forward slash included request = new MockHttpServletRequest("GET", "welcome.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); assertThat(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .isEqualTo("welcome.html"); // testing some ????? behavior request = new MockHttpServletRequest("GET", "/pathmatchingAA.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); assertThat(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .isEqualTo("pathmatchingAA.html"); // testing some ????? behavior request = new MockHttpServletRequest("GET", "/pathmatchingA.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); assertThat(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .isEqualTo("/pathmatchingA.html"); // testing some ????? behavior request = new MockHttpServletRequest("GET", "/administrator/pathmatching.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); // testing simple /**/behavior request = new MockHttpServletRequest("GET", "/administrator/test/pathmatching.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); // this should not match because of the administratorT request = new MockHttpServletRequest("GET", "/administratort/pathmatching.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); // this should match because of *.jsp request = new MockHttpServletRequest("GET", "/bla.jsp"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); // should match because exact pattern is there request = new MockHttpServletRequest("GET", "/administrator/another/bla.xml"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); // should not match, because there's not .gif extension in there request = new MockHttpServletRequest("GET", "/administrator/another/bla.gif"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); // should match because there testlast* in there request = new MockHttpServletRequest("GET", "/administrator/test/testlastbit"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); // but this not, because it's testlast and not testla request = new MockHttpServletRequest("GET", "/administrator/test/testla"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); if (mapping.getPatternParser() != null) { request = new MockHttpServletRequest("GET", "/administrator/testing/longer/bla"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); request = new MockHttpServletRequest("GET", "/administrator/testing/longer/test.jsp"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); } request = new MockHttpServletRequest("GET", "/administrator/testing/longer2/notmatching/notmatching"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); request = new MockHttpServletRequest("GET", "/shortpattern/testing/toolong"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); request = new MockHttpServletRequest("GET", "/XXpathXXmatching.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); request = new MockHttpServletRequest("GET", "/pathXXmatching.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); request = new MockHttpServletRequest("GET", "/XpathXXmatching.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); request = new MockHttpServletRequest("GET", "/XXpathmatching.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); request = new MockHttpServletRequest("GET", "/show12.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); request = new MockHttpServletRequest("GET", "/show123.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); request = new MockHttpServletRequest("GET", "/show1.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); request = new MockHttpServletRequest("GET", "/reallyGood-test-is-this.jpeg"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); request = new MockHttpServletRequest("GET", "/reallyGood-tst-is-this.jpeg"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); request = new MockHttpServletRequest("GET", "/testing/test.jpeg"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); request = new MockHttpServletRequest("GET", "/testing/test.jpg"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); request = new MockHttpServletRequest("GET", "/anotherTest"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(bean); request = new MockHttpServletRequest("GET", "/stillAnotherTest"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); // there outofpattern*yeah in the pattern, so this should fail request = new MockHttpServletRequest("GET", "/outofpattern*ye"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); request = new MockHttpServletRequest("GET", "/test't%20est/path'm%20atching.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); assertThat(chain.getHandler()).isSameAs(defaultBean); request = new MockHttpServletRequest("GET", "/test%26t%20est/path%26m%20atching.html"); - chain = getHandler(mapping, wac, request); + chain = getHandler(mapping, request); if (!mapping.getPathPatternHandlerMap().isEmpty()) { assertThat(chain.getHandler()) .as("PathPattern always matches to encoded paths.") @@ -252,7 +252,7 @@ public class PathMatchingUrlHandlerMappingTests { void defaultMapping(HandlerMapping mapping, WebApplicationContext wac) throws Exception { Object bean = wac.getBean("starController"); MockHttpServletRequest req = new MockHttpServletRequest("GET", "/goggog.html"); - HandlerExecutionChain hec = getHandler(mapping, wac, req); + HandlerExecutionChain hec = getHandler(mapping, req); assertThat(hec.getHandler()).isSameAs(bean); } @@ -260,14 +260,13 @@ public class PathMatchingUrlHandlerMappingTests { void mappingExposedInRequest(HandlerMapping mapping, WebApplicationContext wac) throws Exception { Object bean = wac.getBean("mainController"); MockHttpServletRequest req = new MockHttpServletRequest("GET", "/show.html"); - HandlerExecutionChain hec = getHandler(mapping, wac, req); + HandlerExecutionChain hec = getHandler(mapping, req); assertThat(hec.getHandler()).isSameAs(bean); assertThat(req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)) .as("Mapping not exposed").isEqualTo("show.html"); } - private HandlerExecutionChain getHandler( - HandlerMapping mapping, WebApplicationContext wac, MockHttpServletRequest request) + private HandlerExecutionChain getHandler(HandlerMapping mapping, MockHttpServletRequest request) throws Exception { // At runtime this is done by the DispatcherServlet diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolverTests.java index 7f8d8e8f5d2..023f32b291c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Juergen Hoeller * @author Arjen Poutsma */ -public class SimpleMappingExceptionResolverTests { +class SimpleMappingExceptionResolverTests { private SimpleMappingExceptionResolver exceptionResolver; private MockHttpServletRequest request; @@ -45,9 +45,9 @@ public class SimpleMappingExceptionResolverTests { private Exception genericException; @BeforeEach - public void setUp() throws Exception { + void setUp() { exceptionResolver = new SimpleMappingExceptionResolver(); - handler1 = new String(); + handler1 = ""; handler2 = new Object(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); @@ -56,13 +56,13 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void setOrder() { + void setOrder() { exceptionResolver.setOrder(2); assertThat(exceptionResolver.getOrder()).isEqualTo(2); } @Test - public void defaultErrorView() { + void defaultErrorView() { exceptionResolver.setDefaultErrorView("default-view"); ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException); assertThat(mav.getViewName()).isEqualTo("default-view"); @@ -70,7 +70,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void defaultErrorViewDifferentHandler() { + void defaultErrorViewDifferentHandler() { exceptionResolver.setDefaultErrorView("default-view"); exceptionResolver.setMappedHandlers(Collections.singleton(handler1)); ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException); @@ -78,7 +78,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void defaultErrorViewDifferentHandlerClass() { + void defaultErrorViewDifferentHandlerClass() { exceptionResolver.setDefaultErrorView("default-view"); exceptionResolver.setMappedHandlerClasses(String.class); ModelAndView mav = exceptionResolver.resolveException(request, response, handler2, genericException); @@ -86,7 +86,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void nullExceptionAttribute() { + void nullExceptionAttribute() { exceptionResolver.setDefaultErrorView("default-view"); exceptionResolver.setExceptionAttribute(null); ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException); @@ -95,7 +95,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void nullExceptionMappings() { + void nullExceptionMappings() { exceptionResolver.setExceptionMappings(null); exceptionResolver.setDefaultErrorView("default-view"); ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException); @@ -103,14 +103,14 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void noDefaultStatusCode() { + void noDefaultStatusCode() { exceptionResolver.setDefaultErrorView("default-view"); exceptionResolver.resolveException(request, response, handler1, genericException); assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK); } @Test - public void setDefaultStatusCode() { + void setDefaultStatusCode() { exceptionResolver.setDefaultErrorView("default-view"); exceptionResolver.setDefaultStatusCode(HttpServletResponse.SC_BAD_REQUEST); exceptionResolver.resolveException(request, response, handler1, genericException); @@ -118,7 +118,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void noDefaultStatusCodeInInclude() { + void noDefaultStatusCodeInInclude() { exceptionResolver.setDefaultErrorView("default-view"); exceptionResolver.setDefaultStatusCode(HttpServletResponse.SC_BAD_REQUEST); request.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "some path"); @@ -127,7 +127,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void specificStatusCode() { + void specificStatusCode() { exceptionResolver.setDefaultErrorView("default-view"); exceptionResolver.setDefaultStatusCode(HttpServletResponse.SC_BAD_REQUEST); Properties statusCodes = new Properties(); @@ -138,7 +138,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void simpleExceptionMapping() { + void simpleExceptionMapping() { Properties props = new Properties(); props.setProperty("Exception", "error"); exceptionResolver.setWarnLogCategory("HANDLER_EXCEPTION"); @@ -148,7 +148,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void exactExceptionMappingWithHandlerSpecified() { + void exactExceptionMappingWithHandlerSpecified() { Properties props = new Properties(); props.setProperty("java.lang.Exception", "error"); exceptionResolver.setMappedHandlers(Collections.singleton(handler1)); @@ -158,7 +158,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void exactExceptionMappingWithHandlerClassSpecified() { + void exactExceptionMappingWithHandlerClassSpecified() { Properties props = new Properties(); props.setProperty("java.lang.Exception", "error"); exceptionResolver.setMappedHandlerClasses(String.class); @@ -168,7 +168,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void exactExceptionMappingWithHandlerInterfaceSpecified() { + void exactExceptionMappingWithHandlerInterfaceSpecified() { Properties props = new Properties(); props.setProperty("java.lang.Exception", "error"); exceptionResolver.setMappedHandlerClasses(Comparable.class); @@ -178,7 +178,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void simpleExceptionMappingWithHandlerSpecifiedButWrongHandler() { + void simpleExceptionMappingWithHandlerSpecifiedButWrongHandler() { Properties props = new Properties(); props.setProperty("Exception", "error"); exceptionResolver.setMappedHandlers(Collections.singleton(handler1)); @@ -188,7 +188,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void simpleExceptionMappingWithHandlerClassSpecifiedButWrongHandler() { + void simpleExceptionMappingWithHandlerClassSpecifiedButWrongHandler() { Properties props = new Properties(); props.setProperty("Exception", "error"); exceptionResolver.setMappedHandlerClasses(String.class); @@ -198,7 +198,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void simpleExceptionMappingWithExclusion() { + void simpleExceptionMappingWithExclusion() { Properties props = new Properties(); props.setProperty("Exception", "error"); exceptionResolver.setExceptionMappings(props); @@ -208,7 +208,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void missingExceptionInMapping() { + void missingExceptionInMapping() { Properties props = new Properties(); props.setProperty("SomeFooThrowable", "error"); exceptionResolver.setWarnLogCategory("HANDLER_EXCEPTION"); @@ -218,7 +218,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void twoMappings() { + void twoMappings() { Properties props = new Properties(); props.setProperty("java.lang.Exception", "error"); props.setProperty("AnotherException", "another-error"); @@ -229,7 +229,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void twoMappingsOneShortOneLong() { + void twoMappingsOneShortOneLong() { Properties props = new Properties(); props.setProperty("Exception", "error"); props.setProperty("AnotherException", "another-error"); @@ -240,7 +240,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void twoMappingsOneShortOneLongThrowOddException() { + void twoMappingsOneShortOneLongThrowOddException() { Exception oddException = new SomeOddException(); Properties props = new Properties(); props.setProperty("Exception", "error"); @@ -252,7 +252,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void twoMappingsThrowOddExceptionUseLongExceptionMapping() { + void twoMappingsThrowOddExceptionUseLongExceptionMapping() { Exception oddException = new SomeOddException(); Properties props = new Properties(); props.setProperty("java.lang.Exception", "error"); @@ -264,7 +264,7 @@ public class SimpleMappingExceptionResolverTests { } @Test - public void threeMappings() { + void threeMappings() { Exception oddException = new AnotherOddException(); Properties props = new Properties(); props.setProperty("java.lang.Exception", "error"); 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 bb49c98a5eb..57f868e1b63 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -43,10 +43,9 @@ import static org.springframework.web.servlet.HandlerMapping.PATH_WITHIN_HANDLER * @author Rod Johnson * @author Juergen Hoeller */ -public class SimpleUrlHandlerMappingTests { +class SimpleUrlHandlerMappingTests { @Test - @SuppressWarnings("resource") public void handlerBeanNotFound() { MockServletContext sc = new MockServletContext(""); XmlWebApplicationContext root = new XmlWebApplicationContext(); @@ -69,7 +68,7 @@ public class SimpleUrlHandlerMappingTests { } @Test - public void testNewlineInRequest() throws Exception { + void testNewlineInRequest() throws Exception { Object controller = new Object(); UrlPathHelper urlPathHelper = new UrlPathHelper(); urlPathHelper.setUrlDecode(false); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/i18n/SessionLocaleResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/i18n/SessionLocaleResolverTests.java index 60c028b1a9e..2eb24c8494b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/i18n/SessionLocaleResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/i18n/SessionLocaleResolverTests.java @@ -65,14 +65,14 @@ class SessionLocaleResolverTests { } @Test - void resolveLocaleWithoutSession() throws Exception { + void resolveLocaleWithoutSession() { request.addPreferredLocale(Locale.TAIWAN); assertThat(resolver.resolveLocale(request)).isEqualTo(request.getLocale()); } @Test - void resolveLocaleWithoutSessionAndDefaultLocale() throws Exception { + void resolveLocaleWithoutSessionAndDefaultLocale() { request.addPreferredLocale(Locale.TAIWAN); resolver.setDefaultLocale(Locale.GERMAN); @@ -81,7 +81,7 @@ class SessionLocaleResolverTests { } @Test - void setLocaleToNullLocale() throws Exception { + void setLocaleToNullLocale() { request.addPreferredLocale(Locale.TAIWAN); request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, Locale.GERMAN); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/ControllerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/ControllerTests.java index c65b2265b15..c11527c88c9 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/ControllerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/ControllerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -43,10 +43,10 @@ import static org.mockito.Mockito.verify; * @author Rod Johnson * @author Juergen Hoeller */ -public class ControllerTests { +class ControllerTests { @Test - public void parameterizableViewController() throws Exception { + void parameterizableViewController() throws Exception { String viewName = "viewName"; ParameterizableViewController pvc = new ParameterizableViewController(); pvc.setViewName(viewName); @@ -58,21 +58,21 @@ public class ControllerTests { } @Test - public void servletForwardingController() throws Exception { + void servletForwardingController() throws Exception { ServletForwardingController sfc = new ServletForwardingController(); sfc.setServletName("action"); doTestServletForwardingController(sfc, false); } @Test - public void servletForwardingControllerWithInclude() throws Exception { + void servletForwardingControllerWithInclude() throws Exception { ServletForwardingController sfc = new ServletForwardingController(); sfc.setServletName("action"); doTestServletForwardingController(sfc, true); } @Test - public void servletForwardingControllerWithBeanName() throws Exception { + void servletForwardingControllerWithBeanName() throws Exception { ServletForwardingController sfc = new ServletForwardingController(); sfc.setBeanName("action"); doTestServletForwardingController(sfc, false); @@ -109,7 +109,7 @@ public class ControllerTests { } @Test - public void servletWrappingController() throws Exception { + void servletWrappingController() throws Exception { HttpServletRequest request = new MockHttpServletRequest("GET", "/somePath"); HttpServletResponse response = new MockHttpServletResponse(); @@ -137,7 +137,7 @@ public class ControllerTests { } @Test - public void servletWrappingControllerWithBeanName() throws Exception { + void servletWrappingControllerWithBeanName() throws Exception { HttpServletRequest request = new MockHttpServletRequest("GET", "/somePath"); HttpServletResponse response = new MockHttpServletResponse(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/ParameterizableViewControllerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/ParameterizableViewControllerTests.java index 948f75e929b..0a813c1cd61 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/ParameterizableViewControllerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/ParameterizableViewControllerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -34,20 +34,20 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rossen Stoyanchev * @since 3.1.1 */ -public class ParameterizableViewControllerTests { +class ParameterizableViewControllerTests { private ParameterizableViewController controller; private MockHttpServletRequest request; @BeforeEach - public void setup() { + void setup() { this.controller = new ParameterizableViewController(); this.request = new MockHttpServletRequest("GET", "/"); } @Test - public void handleRequestWithViewName() throws Exception { + void handleRequestWithViewName() throws Exception { String viewName = "testView"; this.controller.setViewName(viewName); ModelAndView mav = this.controller.handleRequest(this.request, new MockHttpServletResponse()); @@ -56,14 +56,14 @@ public class ParameterizableViewControllerTests { } @Test - public void handleRequestWithoutViewName() throws Exception { + void handleRequestWithoutViewName() throws Exception { ModelAndView mav = this.controller.handleRequest(this.request, new MockHttpServletResponse()); assertThat(mav.getViewName()).isNull(); assertThat(mav.getModel()).isEmpty(); } @Test - public void handleRequestWithFlashAttributes() throws Exception { + void handleRequestWithFlashAttributes() throws Exception { this.request.setAttribute(DispatcherServlet.INPUT_FLASH_MAP_ATTRIBUTE, new ModelMap("name", "value")); ModelAndView mav = this.controller.handleRequest(this.request, new MockHttpServletResponse()); assertThat(mav.getModel()).hasSize(1); @@ -71,7 +71,7 @@ public class ParameterizableViewControllerTests { } @Test - public void handleRequestHttpOptions() throws Exception { + void handleRequestHttpOptions() throws Exception { this.request.setMethod(HttpMethod.OPTIONS.name()); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView mav = this.controller.handleRequest(this.request, response); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/CglibProxyControllerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/CglibProxyControllerTests.java index 3fbdadb0533..e0d419f7640 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/CglibProxyControllerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/CglibProxyControllerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -44,13 +44,13 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Arjen Poutsma * @since 3.0 */ -public class CglibProxyControllerTests { +class CglibProxyControllerTests { private DispatcherServlet servlet; @Test - public void typeLevel() throws Exception { + void typeLevel() throws Exception { initServlet(TypeLevelImpl.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test"); @@ -60,7 +60,7 @@ public class CglibProxyControllerTests { } @Test - public void methodLevel() throws Exception { + void methodLevel() throws Exception { initServlet(MethodLevelImpl.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test"); @@ -70,7 +70,7 @@ public class CglibProxyControllerTests { } @Test - public void typeAndMethodLevel() throws Exception { + void typeAndMethodLevel() throws Exception { initServlet(TypeAndMethodLevelImpl.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/bookings"); @@ -80,7 +80,6 @@ public class CglibProxyControllerTests { } - @SuppressWarnings("serial") private void initServlet(final Class controllerClass) throws ServletException { servlet = new DispatcherServlet() { @Override diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/JdkProxyControllerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/JdkProxyControllerTests.java index a1de84fb2c8..d8729ca11f8 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/JdkProxyControllerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/JdkProxyControllerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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,13 +42,13 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Arjen Poutsma * @since 3.0 */ -public class JdkProxyControllerTests { +class JdkProxyControllerTests { private DispatcherServlet servlet; @Test - public void typeLevel() throws Exception { + void typeLevel() throws Exception { initServlet(TypeLevelImpl.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test"); @@ -58,7 +58,7 @@ public class JdkProxyControllerTests { } @Test - public void methodLevel() throws Exception { + void methodLevel() throws Exception { initServlet(MethodLevelImpl.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test"); @@ -68,7 +68,7 @@ public class JdkProxyControllerTests { } @Test - public void typeAndMethodLevel() throws Exception { + void typeAndMethodLevel() throws Exception { initServlet(TypeAndMethodLevelImpl.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/bookings"); @@ -78,7 +78,6 @@ public class JdkProxyControllerTests { } - @SuppressWarnings("serial") private void initServlet(final Class controllerclass) throws ServletException { servlet = new DispatcherServlet() { @Override diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolverTests.java index 4c2c0b2f381..b4cc341718c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @author Rossen Stoyanchev */ -public class ResponseStatusExceptionResolverTests { +class ResponseStatusExceptionResolverTests { private final ResponseStatusExceptionResolver exceptionResolver = new ResponseStatusExceptionResolver(); @@ -58,34 +58,34 @@ public class ResponseStatusExceptionResolverTests { @BeforeEach - public void setup() { + void setup() { exceptionResolver.setWarnLogCategory(exceptionResolver.getClass().getName()); } @Test - public void statusCode() { + void statusCode() { StatusCodeException ex = new StatusCodeException(); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertResolved(mav, 400, null); } @Test - public void statusCodeFromComposedResponseStatus() { + void statusCodeFromComposedResponseStatus() { StatusCodeFromComposedResponseStatusException ex = new StatusCodeFromComposedResponseStatusException(); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertResolved(mav, 400, null); } @Test - public void statusCodeAndReason() { + void statusCodeAndReason() { StatusCodeAndReasonException ex = new StatusCodeAndReasonException(); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertResolved(mav, 410, "You suck!"); } @Test - public void statusCodeAndReasonMessage() { + void statusCodeAndReasonMessage() { Locale locale = Locale.CHINESE; LocaleContextHolder.setLocale(locale); try { @@ -103,7 +103,7 @@ public class ResponseStatusExceptionResolverTests { } @Test - public void notAnnotated() { + void notAnnotated() { Exception ex = new Exception(); exceptionResolver.resolveException(request, response, null, ex); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); @@ -119,7 +119,7 @@ public class ResponseStatusExceptionResolverTests { } @Test - public void responseStatusException() { + void responseStatusException() { ResponseStatusException ex = new ResponseStatusException(HttpStatus.BAD_REQUEST); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertResolved(mav, 400, null); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/CompositeRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/CompositeRequestConditionTests.java index 9258f9cb9e9..bf4eefec95f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/CompositeRequestConditionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/CompositeRequestConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * * @author Rossen Stoyanchev */ -public class CompositeRequestConditionTests { +class CompositeRequestConditionTests { private ParamsRequestCondition param1; private ParamsRequestCondition param2; @@ -42,7 +42,7 @@ public class CompositeRequestConditionTests { private HeadersRequestCondition header3; @BeforeEach - public void setup() { + void setup() { this.param1 = new ParamsRequestCondition("param1"); this.param2 = new ParamsRequestCondition("param2"); this.param3 = this.param1.combine(this.param2); @@ -53,7 +53,7 @@ public class CompositeRequestConditionTests { } @Test - public void combine() { + void combine() { CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1, this.header1); CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param2, this.header2); CompositeRequestCondition cond3 = new CompositeRequestCondition(this.param3, this.header3); @@ -62,7 +62,7 @@ public class CompositeRequestConditionTests { } @Test - public void combineEmpty() { + void combineEmpty() { CompositeRequestCondition empty = new CompositeRequestCondition(); CompositeRequestCondition notEmpty = new CompositeRequestCondition(this.param1); @@ -72,7 +72,7 @@ public class CompositeRequestConditionTests { } @Test - public void combineDifferentLength() { + void combineDifferentLength() { CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1); CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param1, this.header1); assertThatIllegalArgumentException().isThrownBy(() -> @@ -80,7 +80,7 @@ public class CompositeRequestConditionTests { } @Test - public void match() { + void match() { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); request.setParameter("param1", "paramValue1"); request.addHeader("header1", "headerValue1"); @@ -95,7 +95,7 @@ public class CompositeRequestConditionTests { } @Test - public void noMatch() { + void noMatch() { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); CompositeRequestCondition cond = new CompositeRequestCondition(this.param1); @@ -103,13 +103,13 @@ public class CompositeRequestConditionTests { } @Test - public void matchEmpty() { + void matchEmpty() { CompositeRequestCondition empty = new CompositeRequestCondition(); assertThat(empty.getMatchingCondition(new MockHttpServletRequest())).isSameAs(empty); } @Test - public void compare() { + void compare() { HttpServletRequest request = new MockHttpServletRequest(); CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1); @@ -120,7 +120,7 @@ public class CompositeRequestConditionTests { } @Test - public void compareEmpty() { + void compareEmpty() { HttpServletRequest request = new MockHttpServletRequest(); CompositeRequestCondition empty = new CompositeRequestCondition(); @@ -132,7 +132,7 @@ public class CompositeRequestConditionTests { } @Test - public void compareDifferentLength() { + void compareDifferentLength() { CompositeRequestCondition cond1 = new CompositeRequestCondition(this.param1); CompositeRequestCondition cond2 = new CompositeRequestCondition(this.param1, this.header1); assertThatIllegalArgumentException().isThrownBy(() -> diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestConditionTests.java index 57ce2175960..4f59e95c5c9 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestConditionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Arjen Poutsma */ -public class ConsumesRequestConditionTests { +class ConsumesRequestConditionTests { @Test - public void consumesMatch() { + void consumesMatch() { ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -43,7 +43,7 @@ public class ConsumesRequestConditionTests { } @Test - public void negatedConsumesMatch() { + void negatedConsumesMatch() { ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -53,13 +53,13 @@ public class ConsumesRequestConditionTests { } @Test - public void getConsumableMediaTypesNegatedExpression() { + void getConsumableMediaTypesNegatedExpression() { ConsumesRequestCondition condition = new ConsumesRequestCondition("!application/xml"); assertThat(condition.getConsumableMediaTypes()).isEqualTo(Collections.emptySet()); } @Test - public void consumesWildcardMatch() { + void consumesWildcardMatch() { ConsumesRequestCondition condition = new ConsumesRequestCondition("text/*"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -69,7 +69,7 @@ public class ConsumesRequestConditionTests { } @Test - public void consumesMultipleMatch() { + void consumesMultipleMatch() { ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -79,7 +79,7 @@ public class ConsumesRequestConditionTests { } @Test - public void consumesSingleNoMatch() { + void consumesSingleNoMatch() { ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -114,7 +114,7 @@ public class ConsumesRequestConditionTests { } @Test - public void consumesParseError() { + void consumesParseError() { ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -124,7 +124,7 @@ public class ConsumesRequestConditionTests { } @Test - public void consumesParseErrorWithNegation() { + void consumesParseErrorWithNegation() { ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -155,7 +155,7 @@ public class ConsumesRequestConditionTests { } @Test - public void compareToSingle() { + void compareToSingle() { MockHttpServletRequest request = new MockHttpServletRequest(); ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain"); @@ -169,7 +169,7 @@ public class ConsumesRequestConditionTests { } @Test - public void compareToMultiple() { + void compareToMultiple() { MockHttpServletRequest request = new MockHttpServletRequest(); ConsumesRequestCondition condition1 = new ConsumesRequestCondition("*/*", "text/plain"); @@ -184,7 +184,7 @@ public class ConsumesRequestConditionTests { @Test - public void combine() { + void combine() { ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain"); ConsumesRequestCondition condition2 = new ConsumesRequestCondition("application/xml"); @@ -193,7 +193,7 @@ public class ConsumesRequestConditionTests { } @Test - public void combineWithDefault() { + void combineWithDefault() { ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain"); ConsumesRequestCondition condition2 = new ConsumesRequestCondition(); @@ -202,7 +202,7 @@ public class ConsumesRequestConditionTests { } @Test - public void parseConsumesAndHeaders() { + void parseConsumesAndHeaders() { String[] consumes = new String[] {"text/plain"}; String[] headers = new String[]{"foo=bar", "content-type=application/xml,application/pdf"}; ConsumesRequestCondition condition = new ConsumesRequestCondition(consumes, headers); @@ -211,7 +211,7 @@ public class ConsumesRequestConditionTests { } @Test - public void getMatchingCondition() { + void getMatchingCondition() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setContentType("text/plain"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/HeadersRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/HeadersRequestConditionTests.java index 6ac85df48aa..720b099eb88 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/HeadersRequestConditionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/HeadersRequestConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,10 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Arjen Poutsma */ -public class HeadersRequestConditionTests { +class HeadersRequestConditionTests { @Test - public void headerEquals() { + void headerEquals() { assertThat(new HeadersRequestCondition("foo")).isEqualTo(new HeadersRequestCondition("foo")); assertThat(new HeadersRequestCondition("FOO")).isEqualTo(new HeadersRequestCondition("foo")); assertThat(new HeadersRequestCondition("bar")).isNotEqualTo(new HeadersRequestCondition("foo")); @@ -40,7 +40,7 @@ public class HeadersRequestConditionTests { } @Test - public void headerPresent() { + void headerPresent() { HeadersRequestCondition condition = new HeadersRequestCondition("accept"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -50,7 +50,7 @@ public class HeadersRequestConditionTests { } @Test - public void headerPresentNoMatch() { + void headerPresentNoMatch() { HeadersRequestCondition condition = new HeadersRequestCondition("foo"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -60,7 +60,7 @@ public class HeadersRequestConditionTests { } @Test - public void headerNotPresent() { + void headerNotPresent() { HeadersRequestCondition condition = new HeadersRequestCondition("!accept"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -69,7 +69,7 @@ public class HeadersRequestConditionTests { } @Test - public void headerValueMatch() { + void headerValueMatch() { HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -79,7 +79,7 @@ public class HeadersRequestConditionTests { } @Test - public void headerValueNoMatch() { + void headerValueNoMatch() { HeadersRequestCondition condition = new HeadersRequestCondition("foo=bar"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -89,7 +89,7 @@ public class HeadersRequestConditionTests { } @Test - public void headerCaseSensitiveValueMatch() { + void headerCaseSensitiveValueMatch() { HeadersRequestCondition condition = new HeadersRequestCondition("foo=Bar"); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -99,7 +99,7 @@ public class HeadersRequestConditionTests { } @Test - public void headerValueMatchNegated() { + void headerValueMatchNegated() { HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar"); MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("foo", "baz"); @@ -108,7 +108,7 @@ public class HeadersRequestConditionTests { } @Test - public void headerValueNoMatchNegated() { + void headerValueNoMatchNegated() { HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar"); MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("foo", "bar"); @@ -117,7 +117,7 @@ public class HeadersRequestConditionTests { } @Test - public void compareTo() { + void compareTo() { MockHttpServletRequest request = new MockHttpServletRequest(); HeadersRequestCondition condition1 = new HeadersRequestCondition("foo", "bar", "baz"); @@ -145,7 +145,7 @@ public class HeadersRequestConditionTests { } @Test - public void compareToWithNegatedMatch() { + void compareToWithNegatedMatch() { MockHttpServletRequest request = new MockHttpServletRequest(); HeadersRequestCondition condition1 = new HeadersRequestCondition("foo!=a"); @@ -155,7 +155,7 @@ public class HeadersRequestConditionTests { } @Test - public void combine() { + void combine() { HeadersRequestCondition condition1 = new HeadersRequestCondition("foo=bar"); HeadersRequestCondition condition2 = new HeadersRequestCondition("foo=baz"); @@ -165,7 +165,7 @@ public class HeadersRequestConditionTests { } @Test - public void getMatchingCondition() { + void getMatchingCondition() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("foo", "bar"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java index 82caf174d3f..d36dd92c23e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java @@ -17,6 +17,7 @@ package org.springframework.web.servlet.mvc.condition; import jakarta.servlet.http.HttpServletRequest; +import org.assertj.core.api.StringAssert; import org.junit.jupiter.api.Test; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; @@ -30,20 +31,19 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class PathPatternsRequestConditionTests { +class PathPatternsRequestConditionTests { private static final PathPatternParser parser = new PathPatternParser(); @Test void prependSlash() { - assertThat(createCondition("foo").getPatternValues()).element(0) - .isEqualTo("/foo"); + assertThat(createCondition("foo").getPatternValues()).containsExactly("/foo"); } @Test void prependNonEmptyPatternsOnly() { - assertThat(createCondition("").getPatternValues()).element(0).asString() + assertThat(createCondition("").getPatternValues(), StringAssert.class).element(0) .as("Do not prepend empty patterns (SPR-8255)").isEmpty(); } @@ -138,7 +138,7 @@ public class PathPatternsRequestConditionTests { PathPatternsRequestCondition match = condition.getMatchingCondition(request); assertThat(match).isNotNull(); - assertThat(match.getPatternValues()).element(0).as("Should match by default").isEqualTo("/foo"); + assertThat(match.getPatternValues()).containsExactly("/foo"); PathPatternParser strictParser = new PathPatternParser(); strictParser.setMatchOptionalTrailingSeparator(false); 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 5ebacdf4232..0ff29a96051 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 @@ -19,6 +19,7 @@ package org.springframework.web.servlet.mvc.condition; import java.util.Collections; import jakarta.servlet.http.HttpServletRequest; +import org.assertj.core.api.StringAssert; import org.junit.jupiter.api.Test; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; @@ -35,13 +36,12 @@ class PatternsRequestConditionTests { @Test void prependSlash() { - assertThat(new PatternsRequestCondition("foo").getPatterns()).element(0) - .isEqualTo("/foo"); + assertThat(new PatternsRequestCondition("foo").getPatterns()).containsExactly("/foo"); } @Test void prependNonEmptyPatternsOnly() { - assertThat(new PatternsRequestCondition("").getPatterns()).element(0).asString() + assertThat(new PatternsRequestCondition("").getPatterns(), StringAssert.class).element(0) .as("Do not prepend empty patterns (SPR-8255)").isEmpty(); } @@ -122,7 +122,7 @@ class PatternsRequestConditionTests { PatternsRequestCondition match = condition.getMatchingCondition(request); assertThat(match).isNotNull(); - assertThat(match.getPatterns()).element(0).isEqualTo("/{foo}.*"); + assertThat(match.getPatterns()).containsExactly("/{foo}.*"); useSuffixPatternMatch = false; condition = new PatternsRequestCondition( @@ -130,7 +130,7 @@ class PatternsRequestConditionTests { match = condition.getMatchingCondition(request); assertThat(match).isNotNull(); - assertThat(match.getPatterns()).element(0).isEqualTo("/{foo}"); + assertThat(match.getPatterns()).containsExactly("/{foo}"); } @Test // SPR-8410 @@ -143,13 +143,13 @@ class PatternsRequestConditionTests { PatternsRequestCondition match = condition.getMatchingCondition(request); assertThat(match).isNotNull(); - assertThat(match.getPatterns()).element(0).isEqualTo("/jobs/{jobName}"); + assertThat(match.getPatterns()).containsExactly("/jobs/{jobName}"); request = initRequest("/jobs/my.job.json"); match = condition.getMatchingCondition(request); assertThat(match).isNotNull(); - assertThat(match.getPatterns()).element(0).isEqualTo("/jobs/{jobName}.json"); + assertThat(match.getPatterns()).containsExactly("/jobs/{jobName}.json"); } @Test @@ -177,13 +177,13 @@ class PatternsRequestConditionTests { PatternsRequestCondition match = condition.getMatchingCondition(request); assertThat(match).isNotNull(); - assertThat(match.getPatterns()).element(0).as("Should match by default").isEqualTo("/foo/"); + assertThat(match.getPatterns()).containsExactly("/foo/"); condition = new PatternsRequestCondition(new String[] {"/foo"}, true, null); match = condition.getMatchingCondition(request); assertThat(match).isNotNull(); - assertThat(match.getPatterns()).element(0) + assertThat(match.getPatterns(), StringAssert.class).element(0) .as("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)") .isEqualTo("/foo/"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/ProducesRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/ProducesRequestConditionTests.java index f3f540138e3..b08a4011b15 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/ProducesRequestConditionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/ProducesRequestConditionTests.java @@ -38,10 +38,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Arjen Poutsma * @author Rossen Stoyanchev */ -public class ProducesRequestConditionTests { +class ProducesRequestConditionTests { @Test - public void match() { + void match() { ProducesRequestCondition condition = new ProducesRequestCondition("text/plain"); HttpServletRequest request = createRequest("text/plain"); @@ -49,7 +49,7 @@ public class ProducesRequestConditionTests { } @Test - public void matchNegated() { + void matchNegated() { ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain"); HttpServletRequest request = createRequest("text/plain"); @@ -57,7 +57,7 @@ public class ProducesRequestConditionTests { } @Test - public void matchNegatedWithoutAcceptHeader() { + void matchNegatedWithoutAcceptHeader() { ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain"); assertThat(condition.getMatchingCondition(new MockHttpServletRequest())).isNotNull(); @@ -65,13 +65,13 @@ public class ProducesRequestConditionTests { } @Test - public void getProducibleMediaTypes() { + void getProducibleMediaTypes() { ProducesRequestCondition condition = new ProducesRequestCondition("!application/xml"); assertThat(condition.getProducibleMediaTypes()).isEqualTo(Collections.emptySet()); } @Test - public void matchWildcard() { + void matchWildcard() { ProducesRequestCondition condition = new ProducesRequestCondition("text/*"); HttpServletRequest request = createRequest("text/plain"); @@ -79,7 +79,7 @@ public class ProducesRequestConditionTests { } @Test - public void matchMultiple() { + void matchMultiple() { ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml"); HttpServletRequest request = createRequest("text/plain"); @@ -87,7 +87,7 @@ public class ProducesRequestConditionTests { } @Test - public void matchSingle() { + void matchSingle() { ProducesRequestCondition condition = new ProducesRequestCondition("text/plain"); HttpServletRequest request = createRequest("application/xml"); @@ -115,7 +115,7 @@ public class ProducesRequestConditionTests { } @Test - public void matchParseError() { + void matchParseError() { ProducesRequestCondition condition = new ProducesRequestCondition("text/plain"); HttpServletRequest request = createRequest("bogus"); @@ -123,7 +123,7 @@ public class ProducesRequestConditionTests { } @Test - public void matchParseErrorWithNegation() { + void matchParseErrorWithNegation() { ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain"); HttpServletRequest request = createRequest("bogus"); @@ -131,7 +131,7 @@ public class ProducesRequestConditionTests { } @Test - public void matchByRequestParameter() { + void matchByRequestParameter() { String[] produces = {"text/plain"}; String[] headers = {}; ProducesRequestCondition condition = new ProducesRequestCondition(produces, headers); @@ -168,7 +168,7 @@ public class ProducesRequestConditionTests { } @Test - public void compareTo() { + void compareTo() { ProducesRequestCondition html = new ProducesRequestCondition("text/html"); ProducesRequestCondition xml = new ProducesRequestCondition("application/xml"); ProducesRequestCondition none = new ProducesRequestCondition(); @@ -200,7 +200,7 @@ public class ProducesRequestConditionTests { } @Test - public void compareToWithSingleExpression() { + void compareToWithSingleExpression() { HttpServletRequest request = createRequest("text/plain"); ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain"); @@ -214,7 +214,7 @@ public class ProducesRequestConditionTests { } @Test - public void compareToMultipleExpressions() { + void compareToMultipleExpressions() { ProducesRequestCondition condition1 = new ProducesRequestCondition("*/*", "text/plain"); ProducesRequestCondition condition2 = new ProducesRequestCondition("text/*", "text/plain;q=0.7"); @@ -228,7 +228,7 @@ public class ProducesRequestConditionTests { } @Test - public void compareToMultipleExpressionsAndMultipleAcceptHeaderValues() { + void compareToMultipleExpressionsAndMultipleAcceptHeaderValues() { ProducesRequestCondition condition1 = new ProducesRequestCondition("text/*", "text/plain"); ProducesRequestCondition condition2 = new ProducesRequestCondition("application/*", "application/xml"); @@ -252,7 +252,7 @@ public class ProducesRequestConditionTests { // SPR-8536 @Test - public void compareToMediaTypeAll() { + void compareToMediaTypeAll() { MockHttpServletRequest request = new MockHttpServletRequest(); ProducesRequestCondition condition1 = new ProducesRequestCondition(); @@ -287,7 +287,7 @@ public class ProducesRequestConditionTests { // SPR-9021 @Test - public void compareToMediaTypeAllWithParameter() { + void compareToMediaTypeAllWithParameter() { HttpServletRequest request = createRequest("*/*;q=0.9"); ProducesRequestCondition condition1 = new ProducesRequestCondition(); @@ -298,7 +298,7 @@ public class ProducesRequestConditionTests { } @Test - public void compareToEqualMatch() { + void compareToEqualMatch() { HttpServletRequest request = createRequest("text/*"); ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain"); @@ -312,7 +312,7 @@ public class ProducesRequestConditionTests { } @Test - public void compareEmptyInvalidAccept() { + void compareEmptyInvalidAccept() { HttpServletRequest request = createRequest("foo"); ProducesRequestCondition condition1 = new ProducesRequestCondition(); @@ -323,7 +323,7 @@ public class ProducesRequestConditionTests { } @Test - public void combine() { + void combine() { ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain"); ProducesRequestCondition condition2 = new ProducesRequestCondition("application/xml"); @@ -332,7 +332,7 @@ public class ProducesRequestConditionTests { } @Test - public void combineWithDefault() { + void combineWithDefault() { ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain"); ProducesRequestCondition condition2 = new ProducesRequestCondition(); @@ -341,7 +341,7 @@ public class ProducesRequestConditionTests { } @Test - public void instantiateWithProducesAndHeaderConditions() { + void instantiateWithProducesAndHeaderConditions() { String[] produces = new String[] {"text/plain"}; String[] headers = new String[]{"foo=bar", "accept=application/xml,application/pdf"}; ProducesRequestCondition condition = new ProducesRequestCondition(produces, headers); @@ -350,7 +350,7 @@ public class ProducesRequestConditionTests { } @Test - public void getMatchingCondition() { + void getMatchingCondition() { HttpServletRequest request = createRequest("text/plain"); ProducesRequestCondition condition = new ProducesRequestCondition("text/plain", "application/xml"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolderTests.java index 6aa86cbfa90..3d1b1d902ba 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/RequestConditionHolderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * * @author Rossen Stoyanchev */ -public class RequestConditionHolderTests { +class RequestConditionHolderTests { @Test - public void combine() { + void combine() { RequestConditionHolder params1 = new RequestConditionHolder(new ParamsRequestCondition("name1")); RequestConditionHolder params2 = new RequestConditionHolder(new ParamsRequestCondition("name2")); RequestConditionHolder expected = new RequestConditionHolder(new ParamsRequestCondition("name1", "name2")); @@ -42,7 +42,7 @@ public class RequestConditionHolderTests { } @Test - public void combineEmpty() { + void combineEmpty() { RequestConditionHolder empty = new RequestConditionHolder(null); RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name")); @@ -52,7 +52,7 @@ public class RequestConditionHolderTests { } @Test - public void combineIncompatible() { + void combineIncompatible() { RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name")); RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name")); assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> @@ -60,7 +60,7 @@ public class RequestConditionHolderTests { } @Test - public void match() { + void match() { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); request.setParameter("name1", "value1"); @@ -72,7 +72,7 @@ public class RequestConditionHolderTests { } @Test - public void noMatch() { + void noMatch() { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); RequestMethodsRequestCondition rm = new RequestMethodsRequestCondition(RequestMethod.POST); @@ -82,13 +82,13 @@ public class RequestConditionHolderTests { } @Test - public void matchEmpty() { + void matchEmpty() { RequestConditionHolder empty = new RequestConditionHolder(null); assertThat(empty.getMatchingCondition(new MockHttpServletRequest())).isSameAs(empty); } @Test - public void compare() { + void compare() { HttpServletRequest request = new MockHttpServletRequest(); RequestConditionHolder params11 = new RequestConditionHolder(new ParamsRequestCondition("1")); @@ -99,7 +99,7 @@ public class RequestConditionHolderTests { } @Test - public void compareEmpty() { + void compareEmpty() { HttpServletRequest request = new MockHttpServletRequest(); RequestConditionHolder empty = new RequestConditionHolder(null); @@ -112,7 +112,7 @@ public class RequestConditionHolderTests { } @Test - public void compareIncompatible() { + void compareIncompatible() { RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name")); RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name")); assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestConditionTests.java index 8efe6c784c7..38e05c294f0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestConditionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -38,24 +38,24 @@ import static org.springframework.web.bind.annotation.RequestMethod.PUT; * @author Arjen Poutsma * @author Rossen Stoyanchev */ -public class RequestMethodsRequestConditionTests { +class RequestMethodsRequestConditionTests { @Test - public void getMatchingCondition() { + void getMatchingCondition() { testMatch(new RequestMethodsRequestCondition(GET), GET); testMatch(new RequestMethodsRequestCondition(GET, POST), GET); testNoMatch(new RequestMethodsRequestCondition(GET), POST); } @Test - public void getMatchingConditionWithHttpHead() { + void getMatchingConditionWithHttpHead() { testMatch(new RequestMethodsRequestCondition(HEAD), HEAD); testMatch(new RequestMethodsRequestCondition(GET), GET); testNoMatch(new RequestMethodsRequestCondition(POST), HEAD); } @Test - public void getMatchingConditionWithEmptyConditions() { + void getMatchingConditionWithEmptyConditions() { RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition(); for (RequestMethod method : RequestMethod.values()) { if (method != OPTIONS) { @@ -67,14 +67,14 @@ public class RequestMethodsRequestConditionTests { } @Test - public void getMatchingConditionWithCustomMethod() { + void getMatchingConditionWithCustomMethod() { HttpServletRequest request = new MockHttpServletRequest("PROPFIND", ""); assertThat(new RequestMethodsRequestCondition().getMatchingCondition(request)).isNotNull(); assertThat(new RequestMethodsRequestCondition(GET, POST).getMatchingCondition(request)).isNull(); } @Test - public void getMatchingConditionWithCorsPreFlight() throws Exception { + void getMatchingConditionWithCorsPreFlight() { MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", ""); request.addHeader("Origin", "https://example.com"); request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "PUT"); @@ -85,7 +85,7 @@ public class RequestMethodsRequestConditionTests { } @Test // SPR-14410 - public void getMatchingConditionWithHttpOptionsInErrorDispatch() throws Exception { + public void getMatchingConditionWithHttpOptionsInErrorDispatch() { MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/path"); request.setDispatcherType(DispatcherType.ERROR); @@ -97,7 +97,7 @@ public class RequestMethodsRequestConditionTests { } @Test - public void compareTo() { + void compareTo() { RequestMethodsRequestCondition c1 = new RequestMethodsRequestCondition(GET, HEAD); RequestMethodsRequestCondition c2 = new RequestMethodsRequestCondition(POST); RequestMethodsRequestCondition c3 = new RequestMethodsRequestCondition(); @@ -118,7 +118,7 @@ public class RequestMethodsRequestConditionTests { } @Test - public void combine() { + void combine() { RequestMethodsRequestCondition condition1 = new RequestMethodsRequestCondition(GET); RequestMethodsRequestCondition condition2 = new RequestMethodsRequestCondition(POST); 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 16361bf1db0..71f569a1ef3 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 @@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class RequestMappingInfoHandlerMethodMappingNamingStrategyTests { +class RequestMappingInfoHandlerMethodMappingNamingStrategyTests { @Test - public void getNameExplicit() { + void getNameExplicit() { Method method = ClassUtils.getMethod(TestController.class, "handle"); HandlerMethod handlerMethod = new HandlerMethod(new TestController(), method); @@ -48,7 +48,7 @@ public class RequestMappingInfoHandlerMethodMappingNamingStrategyTests { } @Test - public void getNameConvention() { + void getNameConvention() { Method method = ClassUtils.getMethod(TestController.class, "handle"); HandlerMethod handlerMethod = new HandlerMethod(new TestController(), method); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoTests.java index cce01d7de94..d2554aa05c0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -204,9 +204,7 @@ class RequestMappingInfoTests { Collections.shuffle(list); list.sort(comparator); - assertThat(list).element(0).isEqualTo(oneMethodOneParam); - assertThat(list).element(1).isEqualTo(oneMethod); - assertThat(list).element(2).isEqualTo(noMethods); + assertThat(list).containsExactly(oneMethodOneParam, oneMethod, noMethods); } @Test @@ -226,9 +224,7 @@ class RequestMappingInfoTests { Collections.shuffle(list); list.sort(comparator); - assertThat(list).element(0).isEqualTo(headMethod); - assertThat(list).element(1).isEqualTo(getMethod); - assertThat(list).element(2).isEqualTo(noMethods); + assertThat(list).containsExactly(headMethod, getMethod, noMethods); } @PathPatternsParameterizedTest diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java index 516ee649b72..90842042767 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -62,7 +62,7 @@ public abstract class AbstractRequestAttributesArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { HttpServletRequest request = new MockHttpServletRequest(); HttpServletResponse response = new MockHttpServletResponse(); this.webRequest = new ServletWebRequest(request, response); @@ -82,13 +82,13 @@ public abstract class AbstractRequestAttributesArgumentResolverTests { @Test - public void supportsParameter() throws Exception { + void supportsParameter() throws Exception { assertThat(this.resolver.supportsParameter(new MethodParameter(this.handleMethod, 0))).isTrue(); assertThat(this.resolver.supportsParameter(new MethodParameter(this.handleMethod, -1))).isFalse(); } @Test - public void resolve() throws Exception { + void resolve() throws Exception { MethodParameter param = initMethodParameter(0); assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() -> testResolveArgument(param)) @@ -100,7 +100,7 @@ public abstract class AbstractRequestAttributesArgumentResolverTests { } @Test - public void resolveWithName() throws Exception { + void resolveWithName() throws Exception { MethodParameter param = initMethodParameter(1); Foo foo = new Foo(); this.webRequest.setAttribute("specialFoo", foo, getScope()); @@ -108,7 +108,7 @@ public abstract class AbstractRequestAttributesArgumentResolverTests { } @Test - public void resolveNotRequired() throws Exception { + void resolveNotRequired() throws Exception { MethodParameter param = initMethodParameter(2); assertThat(testResolveArgument(param)).isNull(); @@ -118,7 +118,7 @@ public abstract class AbstractRequestAttributesArgumentResolverTests { } @Test - public void resolveOptional() throws Exception { + void resolveOptional() throws Exception { WebDataBinder dataBinder = new WebRequestDataBinder(null); dataBinder.setConversionService(new DefaultConversionService()); WebDataBinderFactory factory = mock(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractServletHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractServletHandlerMethodTests.java index 1f7ec54b519..424abca3094 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractServletHandlerMethodTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractServletHandlerMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -54,7 +54,7 @@ public abstract class AbstractServletHandlerMethodTests { } @AfterEach - public void tearDown() { + void tearDown() { this.servlet = null; } @@ -68,7 +68,6 @@ public abstract class AbstractServletHandlerMethodTests { return initDispatcherServlet(controllerClass, usePathPatterns, null); } - @SuppressWarnings("serial") WebApplicationContext initDispatcherServlet( @Nullable Class controllerClass, boolean usePathPatterns, @Nullable ApplicationContextInitializer initializer) diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java index 03266161d90..b986ac6da79 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultReturnValueHandlerTests.java @@ -40,7 +40,7 @@ import static org.springframework.web.testfixture.method.ResolvableMethod.on; * * @author Rossen Stoyanchev */ -public class DeferredResultReturnValueHandlerTests { +class DeferredResultReturnValueHandlerTests { private DeferredResultMethodReturnValueHandler handler; @@ -50,7 +50,7 @@ public class DeferredResultReturnValueHandlerTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { this.handler = new DeferredResultMethodReturnValueHandler(); this.request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); @@ -76,12 +76,12 @@ public class DeferredResultReturnValueHandlerTests { } @Test - public void doesNotSupportReturnType() throws Exception { + void doesNotSupportReturnType() { assertThat(this.handler.supportsReturnType(on(TestController.class).resolveReturnType(String.class))).isFalse(); } @Test - public void deferredResult() throws Exception { + void deferredResult() throws Exception { DeferredResult result = new DeferredResult<>(); IllegalStateException ex = new IllegalStateException(); testHandle(result, DeferredResult.class, () -> result.setErrorResult(ex), ex); @@ -97,13 +97,13 @@ public class DeferredResultReturnValueHandlerTests { } @Test - public void completableFuture() throws Exception { + void completableFuture() throws Exception { CompletableFuture future = new CompletableFuture<>(); testHandle(future, CompletableFuture.class, () -> future.complete("foo"), "foo"); } @Test - public void deferredResultWithError() throws Exception { + void deferredResultWithError() throws Exception { DeferredResult result = new DeferredResult<>(); testHandle(result, DeferredResult.class, () -> result.setResult("foo"), "foo"); } @@ -119,7 +119,7 @@ public class DeferredResultReturnValueHandlerTests { } @Test - public void completableFutureWithError() throws Exception { + void completableFutureWithError() throws Exception { CompletableFuture future = new CompletableFuture<>(); IllegalStateException ex = new IllegalStateException(); testHandle(future, CompletableFuture.class, () -> future.completeExceptionally(ex), ex); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinderTests.java index 9371009aadc..b2295a12e72 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.web.bind.ServletRequestDataBinder; -import org.springframework.web.bind.WebDataBinder; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; @@ -35,32 +34,32 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class ExtendedServletRequestDataBinderTests { +class ExtendedServletRequestDataBinderTests { private MockHttpServletRequest request; @BeforeEach - public void setup() { + void setup() { this.request = new MockHttpServletRequest(); } @Test - public void createBinder() throws Exception { + void createBinder() { Map uriTemplateVars = new HashMap<>(); uriTemplateVars.put("name", "nameValue"); uriTemplateVars.put("age", "25"); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); TestBean target = new TestBean(); - WebDataBinder binder = new ExtendedServletRequestDataBinder(target, ""); - ((ServletRequestDataBinder) binder).bind(request); + ServletRequestDataBinder binder = new ExtendedServletRequestDataBinder(target, ""); + binder.bind(request); assertThat(target.getName()).isEqualTo("nameValue"); assertThat(target.getAge()).isEqualTo(25); } @Test - public void uriTemplateVarAndRequestParam() throws Exception { + void uriTemplateVarAndRequestParam() { request.addParameter("age", "35"); Map uriTemplateVars = new HashMap<>(); @@ -69,18 +68,18 @@ public class ExtendedServletRequestDataBinderTests { request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); TestBean target = new TestBean(); - WebDataBinder binder = new ExtendedServletRequestDataBinder(target, ""); - ((ServletRequestDataBinder) binder).bind(request); + ServletRequestDataBinder binder = new ExtendedServletRequestDataBinder(target, ""); + binder.bind(request); assertThat(target.getName()).isEqualTo("nameValue"); assertThat(target.getAge()).isEqualTo(35); } @Test - public void noUriTemplateVars() throws Exception { + void noUriTemplateVars() { TestBean target = new TestBean(); - WebDataBinder binder = new ExtendedServletRequestDataBinder(target, ""); - ((ServletRequestDataBinder) binder).bind(request); + ServletRequestDataBinder binder = new ExtendedServletRequestDataBinder(target, ""); + binder.bind(request); assertThat(target.getName()).isNull(); assertThat(target.getAge()).isEqualTo(0); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java index 9e397b71825..2a72be5b8b8 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorMockTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -24,7 +24,6 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.ZoneId; import java.time.ZonedDateTime; -import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -103,16 +102,12 @@ class HttpEntityMethodProcessorMockTests { private HttpEntityMethodProcessor processor; - @SuppressWarnings("unchecked") private HttpMessageConverter stringHttpMessageConverter = mock(); - @SuppressWarnings("unchecked") private HttpMessageConverter resourceMessageConverter = mock(); - @SuppressWarnings("unchecked") private HttpMessageConverter resourceRegionMessageConverter = mock(); - @SuppressWarnings("unchecked") private HttpMessageConverter jsonMessageConverter = mock(); private MethodParameter paramHttpEntity; @@ -247,7 +242,7 @@ class HttpEntityMethodProcessorMockTests { } @Test - void shouldFailResolvingWhenConverterCannotRead() throws Exception { + void shouldFailResolvingWhenConverterCannotRead() { MediaType contentType = TEXT_PLAIN; servletRequest.setMethod("POST"); servletRequest.addHeader("Content-Type", contentType.toString()); @@ -260,7 +255,7 @@ class HttpEntityMethodProcessorMockTests { } @Test - void shouldFailResolvingWhenContentTypeNotSupported() throws Exception { + void shouldFailResolvingWhenContentTypeNotSupported() { servletRequest.setMethod("POST"); servletRequest.setContent("some content".getBytes(StandardCharsets.UTF_8)); assertThatExceptionOfType(HttpMediaTypeNotSupportedException.class).isThrownBy(() -> @@ -378,7 +373,7 @@ class HttpEntityMethodProcessorMockTests { } @Test - void shouldFailHandlingWhenContentTypeNotSupported() throws Exception { + void shouldFailHandlingWhenContentTypeNotSupported() { String body = "Foo"; ResponseEntity returnValue = new ResponseEntity<>(body, HttpStatus.OK); MediaType accepted = MediaType.APPLICATION_ATOM_XML; @@ -426,7 +421,7 @@ class HttpEntityMethodProcessorMockTests { } @Test - void shouldFailHandlingWhenConverterCannotWrite() throws Exception { + void shouldFailHandlingWhenConverterCannotWrite() { String body = "Foo"; ResponseEntity returnValue = new ResponseEntity<>(body, HttpStatus.OK); MediaType accepted = TEXT_PLAIN; @@ -442,7 +437,7 @@ class HttpEntityMethodProcessorMockTests { } @Test // SPR-9142 - void shouldFailHandlingWhenAcceptHeaderIllegal() throws Exception { + void shouldFailHandlingWhenAcceptHeaderIllegal() { ResponseEntity returnValue = new ResponseEntity<>("Body", HttpStatus.ACCEPTED); servletRequest.addHeader("Accept", "01"); @@ -474,7 +469,7 @@ class HttpEntityMethodProcessorMockTests { ArgumentCaptor outputMessage = ArgumentCaptor.forClass(HttpOutputMessage.class); verify(stringHttpMessageConverter).write(eq("body"), eq(TEXT_PLAIN), outputMessage.capture()); assertThat(mavContainer.isRequestHandled()).isTrue(); - assertThat(outputMessage.getValue().getHeaders().get("header")).element(0).isEqualTo("headerValue"); + assertThat(outputMessage.getValue().getHeaders().get("header")).containsExactly("headerValue"); } @Test @@ -739,7 +734,7 @@ class HttpEntityMethodProcessorMockTests { ZonedDateTime dateTime = ofEpochMilli(new Date().getTime()).atZone(GMT); servletRequest.addHeader(HttpHeaders.IF_UNMODIFIED_SINCE, RFC_1123_DATE_TIME.format(dateTime)); - long justModified = dateTime.plus(1, ChronoUnit.SECONDS).toEpochSecond() * 1000; + long justModified = dateTime.plusSeconds(1).toEpochSecond() * 1000; ResponseEntity returnValue = ResponseEntity.ok() .lastModified(justModified).body("body"); initStringMessageConversion(TEXT_PLAIN); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorTests.java index d284dd0a748..897014115c0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -18,6 +18,7 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.io.Serializable; import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -82,7 +83,7 @@ public class HttpEntityMethodProcessorTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { Method method = getClass().getDeclaredMethod("handle", HttpEntity.class, HttpEntity.class); paramList = new MethodParameter(method, 0); paramSimpleBean = new MethodParameter(method, 1); @@ -97,9 +98,9 @@ public class HttpEntityMethodProcessorTests { @Test - public void resolveArgument() throws Exception { + void resolveArgument() throws Exception { String content = "{\"name\" : \"Jad\"}"; - this.servletRequest.setContent(content.getBytes("UTF-8")); + this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8)); this.servletRequest.setContentType("application/json"); List> converters = new ArrayList<>(); @@ -131,9 +132,9 @@ public class HttpEntityMethodProcessorTests { } @Test - public void resolveGenericArgument() throws Exception { + void resolveGenericArgument() throws Exception { String content = "[{\"name\" : \"Jad\"}, {\"name\" : \"Robert\"}]"; - this.servletRequest.setContent(content.getBytes("UTF-8")); + this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8)); this.servletRequest.setContentType("application/json"); List> converters = new ArrayList<>(); @@ -150,13 +151,13 @@ public class HttpEntityMethodProcessorTests { } @Test - public void resolveArgumentTypeVariable() throws Exception { + void resolveArgumentTypeVariable() throws Exception { Method method = MySimpleParameterizedController.class.getMethod("handleDto", HttpEntity.class); HandlerMethod handlerMethod = new HandlerMethod(new MySimpleParameterizedController(), method); MethodParameter methodParam = handlerMethod.getMethodParameters()[0]; String content = "{\"name\" : \"Jad\"}"; - this.servletRequest.setContent(content.getBytes("UTF-8")); + this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8)); this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE); List> converters = new ArrayList<>(); @@ -318,7 +319,7 @@ public class HttpEntityMethodProcessorTests { } - private final class ValidatingBinderFactory implements WebDataBinderFactory { + private static final class ValidatingBinderFactory implements WebDataBinderFactory { @Override public WebDataBinder createBinder(NativeWebRequest webRequest, @Nullable Object target, String objectName) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java index 55551212564..aaed9261185 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -44,7 +44,7 @@ import static org.springframework.web.testfixture.method.MvcAnnotationPredicates * * @author Rossen Stoyanchev */ -public class MatrixVariablesMapMethodArgumentResolverTests { +class MatrixVariablesMapMethodArgumentResolverTests { private MatrixVariableMapMethodArgumentResolver resolver; @@ -58,7 +58,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { this.resolver = new MatrixVariableMapMethodArgumentResolver(); this.mavContainer = new ModelAndViewContainer(); this.request = new MockHttpServletRequest(); @@ -70,7 +70,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests { @Test - public void supportsParameter() { + void supportsParameter() { assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse(); @@ -88,7 +88,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests { } @Test - public void resolveArgument() throws Exception { + void resolveArgument() throws Exception { MultiValueMap params = getVariablesFor("cars"); params.add("colors", "red"); params.add("colors", "green"); @@ -116,7 +116,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests { } @Test - public void resolveArgumentPathVariable() throws Exception { + void resolveArgumentPathVariable() throws Exception { MultiValueMap params1 = getVariablesFor("cars"); params1.add("colors", "red"); params1.add("colors", "purple"); @@ -144,7 +144,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests { } @Test - public void resolveArgumentNoParams() throws Exception { + void resolveArgumentNoParams() throws Exception { MethodParameter param = this.testMethod.annot(matrixAttribute().noName()) .arg(Map.class, String.class, String.class); @@ -157,7 +157,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests { } @Test - public void resolveMultiValueMapArgumentNoParams() throws Exception { + void resolveMultiValueMapArgumentNoParams() throws Exception { MethodParameter param = this.testMethod.annot(matrixAttribute().noPathVar()) .arg(MultiValueMap.class, String.class, String.class); @@ -169,7 +169,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests { } @Test - public void resolveArgumentNoMatch() throws Exception { + void resolveArgumentNoMatch() throws Exception { MultiValueMap params2 = getVariablesFor("planes"); params2.add("colors", "yellow"); params2.add("colors", "orange"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java index acf65388bf4..142d30f79c3 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -44,7 +44,7 @@ import static org.springframework.web.testfixture.method.MvcAnnotationPredicates * Test fixture with {@link MatrixVariableMethodArgumentResolver}. * @author Rossen Stoyanchev */ -public class MatrixVariablesMethodArgumentResolverTests { +class MatrixVariablesMethodArgumentResolverTests { private MatrixVariableMethodArgumentResolver resolver; @@ -58,7 +58,7 @@ public class MatrixVariablesMethodArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { this.resolver = new MatrixVariableMethodArgumentResolver(); this.mavContainer = new ModelAndViewContainer(); this.request = new MockHttpServletRequest(); @@ -70,7 +70,7 @@ public class MatrixVariablesMethodArgumentResolverTests { @Test - public void supportsParameter() { + void supportsParameter() { assertThat(this.resolver.supportsParameter(this.testMethod.arg(String.class))).isFalse(); @@ -82,7 +82,7 @@ public class MatrixVariablesMethodArgumentResolverTests { } @Test - public void resolveArgument() throws Exception { + void resolveArgument() throws Exception { MultiValueMap params = getVariablesFor("cars"); params.add("colors", "red"); params.add("colors", "green"); @@ -93,7 +93,7 @@ public class MatrixVariablesMethodArgumentResolverTests { } @Test - public void resolveArgumentPathVariable() throws Exception { + void resolveArgumentPathVariable() throws Exception { getVariablesFor("cars").add("year", "2006"); getVariablesFor("bikes").add("year", "2005"); MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class); @@ -102,13 +102,13 @@ public class MatrixVariablesMethodArgumentResolverTests { } @Test - public void resolveArgumentDefaultValue() throws Exception { + void resolveArgumentDefaultValue() throws Exception { MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class); assertThat(resolver.resolveArgument(param, this.mavContainer, this.webRequest, null)).isEqualTo("2013"); } @Test - public void resolveArgumentMultipleMatches() throws Exception { + void resolveArgumentMultipleMatches() { getVariablesFor("var1").add("colors", "red"); getVariablesFor("var2").add("colors", "green"); MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class); @@ -118,14 +118,14 @@ public class MatrixVariablesMethodArgumentResolverTests { } @Test - public void resolveArgumentRequired() throws Exception { + void resolveArgumentRequired() { MethodParameter param = this.testMethod.annot(matrixAttribute().noName()).arg(List.class, String.class); assertThatExceptionOfType(ServletRequestBindingException.class).isThrownBy(() -> this.resolver.resolveArgument(param, this.mavContainer, this.webRequest, null)); } @Test - public void resolveArgumentNoMatch() throws Exception { + void resolveArgumentNoMatch() throws Exception { MultiValueMap params = getVariablesFor("cars"); params.add("anotherYear", "2012"); MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MethodValidationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MethodValidationTests.java index 026ecc3cbf5..f678629f16d 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MethodValidationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MethodValidationTests.java @@ -74,7 +74,7 @@ import static org.mockito.Mockito.mock; * * @author Rossen Stoyanchev */ -public class MethodValidationTests { +class MethodValidationTests { private static final Person mockPerson = mock(Person.class); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java index 3980ecfbc95..3b1a591ef50 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class ModelAndViewMethodReturnValueHandlerTests { +class ModelAndViewMethodReturnValueHandlerTests { private ModelAndViewMethodReturnValueHandler handler; @@ -49,7 +49,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { this.handler = new ModelAndViewMethodReturnValueHandler(); this.mavContainer = new ModelAndViewContainer(); this.webRequest = new ServletWebRequest(new MockHttpServletRequest()); @@ -58,13 +58,13 @@ public class ModelAndViewMethodReturnValueHandlerTests { @Test - public void supportsReturnType() throws Exception { + void supportsReturnType() throws Exception { assertThat(handler.supportsReturnType(returnParamModelAndView)).isTrue(); assertThat(handler.supportsReturnType(getReturnValueParam("viewName"))).isFalse(); } @Test - public void handleViewReference() throws Exception { + void handleViewReference() throws Exception { ModelAndView mav = new ModelAndView("viewName", "attrName", "attrValue"); handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest); @@ -73,7 +73,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { } @Test - public void handleViewInstance() throws Exception { + void handleViewInstance() throws Exception { ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue"); handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest); @@ -82,14 +82,14 @@ public class ModelAndViewMethodReturnValueHandlerTests { } @Test - public void handleNull() throws Exception { + void handleNull() throws Exception { handler.handleReturnValue(null, returnParamModelAndView, mavContainer, webRequest); assertThat(mavContainer.isRequestHandled()).isTrue(); } @Test - public void handleRedirectAttributesWithViewReference() throws Exception { + void handleRedirectAttributesWithViewReference() throws Exception { RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap(); mavContainer.setRedirectModel(redirectAttributes); @@ -102,7 +102,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { } @Test - public void handleRedirectAttributesWithViewName() throws Exception { + void handleRedirectAttributesWithViewName() throws Exception { RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap(); mavContainer.setRedirectModel(redirectAttributes); @@ -116,7 +116,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { } @Test - public void handleRedirectAttributesWithCustomPrefix() throws Exception { + void handleRedirectAttributesWithCustomPrefix() throws Exception { RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap(); mavContainer.setRedirectModel(redirectAttributes); @@ -131,7 +131,7 @@ public class ModelAndViewMethodReturnValueHandlerTests { } @Test - public void handleRedirectAttributesWithoutRedirect() throws Exception { + void handleRedirectAttributesWithoutRedirect() throws Exception { RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap(); mavContainer.setRedirectModel(redirectAttributes); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandlerTests.java index 4e62166b3f0..a66c409fd1e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * * @author Rossen Stoyanchev */ -public class ModelAndViewResolverMethodReturnValueHandlerTests { +class ModelAndViewResolverMethodReturnValueHandlerTests { private ModelAndViewResolverMethodReturnValueHandler handler; @@ -53,7 +53,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests { @BeforeEach - public void setup() { + void setup() { mavResolvers = new ArrayList<>(); handler = new ModelAndViewResolverMethodReturnValueHandler(mavResolvers); mavContainer = new ModelAndViewContainer(); @@ -62,7 +62,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests { @Test - public void modelAndViewResolver() throws Exception { + void modelAndViewResolver() throws Exception { MethodParameter returnType = new MethodParameter(getClass().getDeclaredMethod("testBeanReturnValue"), -1); mavResolvers.add(new TestModelAndViewResolver(TestBean.class)); TestBean testBean = new TestBean("name"); @@ -75,7 +75,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests { } @Test - public void modelAndViewResolverUnresolved() throws Exception { + void modelAndViewResolverUnresolved() throws Exception { MethodParameter returnType = new MethodParameter(getClass().getDeclaredMethod("intReturnValue"), -1); mavResolvers.add(new TestModelAndViewResolver(TestBean.class)); assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> @@ -83,7 +83,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests { } @Test - public void handleNull() throws Exception { + void handleNull() throws Exception { MethodParameter returnType = new MethodParameter(getClass().getDeclaredMethod("testBeanReturnValue"), -1); handler.handleReturnValue(null, returnType, mavContainer, request); @@ -93,14 +93,14 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests { } @Test - public void handleSimpleType() throws Exception { + void handleSimpleType() throws Exception { MethodParameter returnType = new MethodParameter(getClass().getDeclaredMethod("intReturnValue"), -1); assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> handler.handleReturnValue(55, returnType, mavContainer, request)); } @Test - public void handleNonSimpleType() throws Exception{ + void handleNonSimpleType() throws Exception{ MethodParameter returnType = new MethodParameter(getClass().getDeclaredMethod("testBeanReturnValue"), -1); handler.handleReturnValue(new TestBean(), returnType, mavContainer, request); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java index 4466e6b658c..14a52fc93e5 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java @@ -91,49 +91,49 @@ public class MvcUriComponentsBuilderTests { @BeforeEach - public void setup() { + void setup() { RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request)); } @AfterEach - public void reset() { + void reset() { RequestContextHolder.resetRequestAttributes(); } @Test - public void fromControllerPlain() { + void fromControllerPlain() { UriComponents uriComponents = fromController(PersonControllerImpl.class).build(); assertThat(uriComponents.toUriString()).endsWith("/people"); } @Test - public void fromControllerUriTemplate() { + void fromControllerUriTemplate() { UriComponents uriComponents = fromController(PersonsAddressesController.class).buildAndExpand(15); assertThat(uriComponents.toUriString()).endsWith("/people/15/addresses"); } @Test - public void fromControllerSubResource() { + void fromControllerSubResource() { UriComponents uriComponents = fromController(PersonControllerImpl.class).pathSegment("something").build(); assertThat(uriComponents.toUriString()).endsWith("/people/something"); } @Test - public void fromControllerTwoTypeLevelMappings() { + void fromControllerTwoTypeLevelMappings() { UriComponents uriComponents = fromController(InvalidController.class).build(); assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/persons"); } @Test - public void fromControllerNotMapped() { + void fromControllerNotMapped() { UriComponents uriComponents = fromController(UnmappedController.class).build(); assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/"); } @Test - public void fromControllerWithCustomBaseUrlViaStaticCall() { + void fromControllerWithCustomBaseUrlViaStaticCall() { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); UriComponents uriComponents = fromController(builder, PersonControllerImpl.class).build(); @@ -142,7 +142,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromControllerWithCustomBaseUrlViaInstance() { + void fromControllerWithCustomBaseUrlViaInstance() { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); MvcUriComponentsBuilder mvcBuilder = relativeTo(builder); UriComponents uriComponents = mvcBuilder.withController(PersonControllerImpl.class).build(); @@ -152,7 +152,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromControllerWithPlaceholder() { + void fromControllerWithPlaceholder() { StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("test", Map.of("context.test.mapping", "people"))); @@ -162,7 +162,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromControllerWithPlaceholderAndMissingValue() { + void fromControllerWithPlaceholderAndMissingValue() { StandardEnvironment environment = new StandardEnvironment(); assertThat(environment.containsProperty("context.test.mapping")).isFalse(); initWebApplicationContext(WebConfig.class, environment); @@ -171,13 +171,13 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromControllerWithPlaceholderAndNoValueResolver() { + void fromControllerWithPlaceholderAndNoValueResolver() { UriComponents uriComponents = fromController(ConfigurablePersonController.class).build(); assertThat(uriComponents.toUriString()).endsWith("/${context.test.mapping}"); } @Test - public void usesForwardedHostAsHostIfHeaderIsSet() throws Exception { + void usesForwardedHostAsHostIfHeaderIsSet() throws Exception { this.request.setScheme("https"); this.request.addHeader("X-Forwarded-Host", "somethingDifferent"); adaptRequestFromForwardedHeaders(); @@ -187,7 +187,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void usesForwardedHostAndPortFromHeader() throws Exception { + void usesForwardedHostAndPortFromHeader() throws Exception { this.request.setScheme("https"); request.addHeader("X-Forwarded-Host", "foobar:8088"); adaptRequestFromForwardedHeaders(); @@ -197,7 +197,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void usesFirstHostOfXForwardedHost() throws Exception { + void usesFirstHostOfXForwardedHost() throws Exception { this.request.setScheme("https"); this.request.addHeader("X-Forwarded-Host", "barfoo:8888, localhost:8088"); adaptRequestFromForwardedHeaders(); @@ -215,7 +215,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodNamePathVariable() { + void fromMethodNamePathVariable() { UriComponents uriComponents = fromMethodName(ControllerWithMethods.class, "methodWithPathVariable", "1").build(); @@ -223,7 +223,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodNameTypeLevelPathVariable() { + void fromMethodNameTypeLevelPathVariable() { this.request.setContextPath("/myapp"); UriComponents uriComponents = fromMethodName( PersonsAddressesController.class, "getAddressesForCountry", "DE").buildAndExpand("1"); @@ -232,7 +232,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodNameTwoPathVariables() { + void fromMethodNameTwoPathVariables() { UriComponents uriComponents = fromMethodName( ControllerWithMethods.class, "methodWithTwoPathVariables", 1, "2009-10-31").build(); @@ -240,7 +240,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodNameWithPathVarAndRequestParam() { + void fromMethodNameWithPathVarAndRequestParam() { UriComponents uriComponents = fromMethodName( ControllerWithMethods.class, "methodForNextPage", "1", 10, 5).build(); @@ -265,7 +265,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodNameInUnmappedController() { + void fromMethodNameInUnmappedController() { UriComponents uriComponents = fromMethodName(UnmappedController.class, "requestMappingMethod").build(); assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/"); @@ -279,7 +279,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodNameWithCustomBaseUrlViaStaticCall() { + void fromMethodNameWithCustomBaseUrlViaStaticCall() { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); UriComponents uriComponents = fromMethodName(builder, ControllerWithMethods.class, "methodWithPathVariable", "1").build(); @@ -289,7 +289,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodNameWithCustomBaseUrlViaInstance() { + void fromMethodNameWithCustomBaseUrlViaInstance() { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); MvcUriComponentsBuilder mvcBuilder = relativeTo(builder); UriComponents uriComponents = mvcBuilder.withMethodName(ControllerWithMethods.class, @@ -317,14 +317,14 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodNameWithMetaAnnotation() { + void fromMethodNameWithMetaAnnotation() { UriComponents uriComponents = fromMethodName(MetaAnnotationController.class, "handleInput").build(); assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/input"); } @Test - public void fromMethodNameConfigurablePath() { + void fromMethodNameConfigurablePath() { StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources().addFirst(new MapPropertySource("test", Map.of("method.test.mapping", "custom"))); @@ -335,7 +335,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallOnSubclass() { + void fromMethodCallOnSubclass() { UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build(); assertThat(uriComponents.toUriString()).startsWith("http://localhost"); @@ -343,7 +343,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallPlain() { + void fromMethodCallPlain() { UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod(null)).build(); assertThat(uriComponents.toUriString()).startsWith("http://localhost"); @@ -351,7 +351,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallPlainWithNoArguments() { + void fromMethodCallPlainWithNoArguments() { UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod()).build(); assertThat(uriComponents.toUriString()).startsWith("http://localhost"); @@ -359,7 +359,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallPlainOnInterface() { + void fromMethodCallPlainOnInterface() { UriComponents uriComponents = fromMethodCall(on(ControllerInterface.class).myMethod(null)).build(); assertThat(uriComponents.toUriString()).startsWith("http://localhost"); @@ -367,7 +367,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallPlainWithNoArgumentsOnInterface() { + void fromMethodCallPlainWithNoArgumentsOnInterface() { UriComponents uriComponents = fromMethodCall(on(ControllerInterface.class).myMethod()).build(); assertThat(uriComponents.toUriString()).startsWith("http://localhost"); @@ -375,7 +375,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallWithTypeLevelUriVars() { + void fromMethodCallWithTypeLevelUriVars() { UriComponents uriComponents = fromMethodCall( on(PersonsAddressesController.class).getAddressesForCountry("DE")).buildAndExpand(15); @@ -383,7 +383,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallWithPathVariable() { + void fromMethodCallWithPathVariable() { UriComponents uriComponents = fromMethodCall( on(ControllerWithMethods.class).methodWithPathVariable("1")).build(); @@ -392,7 +392,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallWithPathVariableAndRequestParams() { + void fromMethodCallWithPathVariableAndRequestParams() { UriComponents uriComponents = fromMethodCall( on(ControllerWithMethods.class).methodForNextPage("1", 10, 5)).build(); @@ -404,7 +404,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallWithPathVariableAndMultiValueRequestParams() { + void fromMethodCallWithPathVariableAndMultiValueRequestParams() { UriComponents uriComponents = fromMethodCall( on(ControllerWithMethods.class).methodWithMultiValueRequestParams("1", Arrays.asList(3, 7), 5)).build(); @@ -416,7 +416,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallWithCustomBaseUrlViaStaticCall() { + void fromMethodCallWithCustomBaseUrlViaStaticCall() { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); UriComponents uriComponents = fromMethodCall(builder, on(ControllerWithMethods.class).myMethod(null)).build(); @@ -425,7 +425,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodCallWithCustomBaseUrlViaInstance() { + void fromMethodCallWithCustomBaseUrlViaInstance() { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("https://example.org:9090/base"); MvcUriComponentsBuilder mvcBuilder = relativeTo(builder); UriComponents result = mvcBuilder.withMethodCall(on(ControllerWithMethods.class).myMethod(null)).build(); @@ -484,7 +484,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMappingNamePlain() { + void fromMappingNamePlain() { initWebApplicationContext(WebConfig.class); this.request.setServerName("example.org"); @@ -497,7 +497,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMappingNameWithCustomBaseUrl() { + void fromMappingNameWithCustomBaseUrl() { initWebApplicationContext(WebConfig.class); UriComponentsBuilder baseUrl = UriComponentsBuilder.fromUriString("https://example.org:9999/base"); @@ -520,7 +520,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMappingNameWithPathWithoutLeadingSlash() { + void fromMappingNameWithPathWithoutLeadingSlash() { initWebApplicationContext(PathWithoutLeadingSlashConfig.class); this.request.setServerName("example.org"); @@ -533,7 +533,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromControllerWithPrefix() { + void fromControllerWithPrefix() { initWebApplicationContext(PathPrefixWebConfig.class); this.request.setScheme("https"); @@ -546,7 +546,7 @@ public class MvcUriComponentsBuilderTests { } @Test - public void fromMethodWithPrefix() { + void fromMethodWithPrefix() { initWebApplicationContext(PathPrefixWebConfig.class); this.request.setScheme("https"); @@ -618,7 +618,7 @@ public class MvcUriComponentsBuilderTests { } @RequestMapping({"/persons", "/people"}) - private class InvalidController { + private static class InvalidController { } @@ -627,7 +627,7 @@ public class MvcUriComponentsBuilderTests { } - private class UnmappedController { + private static class UnmappedController { @RequestMapping public void requestMappingMethod() { @@ -636,7 +636,7 @@ public class MvcUriComponentsBuilderTests { @RequestMapping("/path") - private class UnmappedControllerMethod { + private static class UnmappedControllerMethod { @GetMapping public void getMethod() { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolverTests.java index ede7a522314..520b0ae9504 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class PathVariableMapMethodArgumentResolverTests { +class PathVariableMapMethodArgumentResolverTests { private PathVariableMapMethodArgumentResolver resolver; @@ -55,7 +55,7 @@ public class PathVariableMapMethodArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { resolver = new PathVariableMapMethodArgumentResolver(); mavContainer = new ModelAndViewContainer(); request = new MockHttpServletRequest(); @@ -69,14 +69,14 @@ public class PathVariableMapMethodArgumentResolverTests { @Test - public void supportsParameter() { + void supportsParameter() { assertThat(resolver.supportsParameter(paramMap)).isTrue(); assertThat(resolver.supportsParameter(paramNamedMap)).isFalse(); assertThat(resolver.supportsParameter(paramMapNoAnnot)).isFalse(); } @Test - public void resolveArgument() throws Exception { + void resolveArgument() throws Exception { Map uriTemplateVars = new HashMap<>(); uriTemplateVars.put("name1", "value1"); uriTemplateVars.put("name2", "value2"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolverTests.java index 39ec08e1062..136e261ecc8 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -49,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Rossen Stoyanchev * @author Juergen Hoeller */ -public class PathVariableMethodArgumentResolverTests { +class PathVariableMethodArgumentResolverTests { private PathVariableMethodArgumentResolver resolver; @@ -66,7 +66,7 @@ public class PathVariableMethodArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { resolver = new PathVariableMethodArgumentResolver(); mavContainer = new ModelAndViewContainer(); request = new MockHttpServletRequest(); @@ -81,13 +81,13 @@ public class PathVariableMethodArgumentResolverTests { @Test - public void supportsParameter() { + void supportsParameter() { assertThat(resolver.supportsParameter(paramNamedString)).as("Parameter with @PathVariable annotation").isTrue(); assertThat(resolver.supportsParameter(paramString)).as("Parameter without @PathVariable annotation").isFalse(); } @Test - public void resolveArgument() throws Exception { + void resolveArgument() throws Exception { Map uriTemplateVars = new HashMap<>(); uriTemplateVars.put("name", "value"); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); @@ -103,7 +103,7 @@ public class PathVariableMethodArgumentResolverTests { } @Test - public void resolveArgumentNotRequired() throws Exception { + void resolveArgumentNotRequired() throws Exception { Map uriTemplateVars = new HashMap<>(); uriTemplateVars.put("name", "value"); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); @@ -119,7 +119,7 @@ public class PathVariableMethodArgumentResolverTests { } @Test - public void resolveArgumentWrappedAsOptional() throws Exception { + void resolveArgumentWrappedAsOptional() throws Exception { Map uriTemplateVars = new HashMap<>(); uriTemplateVars.put("name", "value"); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); @@ -141,7 +141,7 @@ public class PathVariableMethodArgumentResolverTests { } @Test - public void resolveArgumentWithExistingPathVars() throws Exception { + void resolveArgumentWithExistingPathVars() throws Exception { Map uriTemplateVars = new HashMap<>(); uriTemplateVars.put("name", "value"); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); @@ -161,18 +161,18 @@ public class PathVariableMethodArgumentResolverTests { } @Test - public void handleMissingValue() throws Exception { + void handleMissingValue() { assertThatExceptionOfType(MissingPathVariableException.class).isThrownBy(() -> resolver.resolveArgument(paramNamedString, mavContainer, webRequest, null)); } @Test - public void nullIfNotRequired() throws Exception { + void nullIfNotRequired() throws Exception { assertThat(resolver.resolveArgument(paramNotRequired, mavContainer, webRequest, null)).isNull(); } @Test - public void wrapEmptyWithOptional() throws Exception { + void wrapEmptyWithOptional() throws Exception { ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandlerTests.java index 33d734996e2..ab0b41a5e2f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandlerTests.java @@ -16,7 +16,6 @@ package org.springframework.web.servlet.mvc.method.annotation; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -62,7 +61,7 @@ import static org.springframework.web.testfixture.method.ResolvableMethod.on; * * @author Rossen Stoyanchev */ -public class ReactiveTypeHandlerTests { +class ReactiveTypeHandlerTests { private ReactiveTypeHandler handler; @@ -74,7 +73,7 @@ public class ReactiveTypeHandlerTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean(); factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = factoryBean.getObject(); @@ -95,13 +94,13 @@ public class ReactiveTypeHandlerTests { @Test - public void supportsType() throws Exception { + void supportsType() { assertThat(this.handler.isReactiveType(Mono.class)).isTrue(); assertThat(this.handler.isReactiveType(Single.class)).isTrue(); } @Test - public void doesNotSupportType() throws Exception { + void doesNotSupportType() { assertThat(this.handler.isReactiveType(String.class)).isFalse(); } @@ -154,7 +153,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void deferredResultSubscriberWithOneValue() throws Exception { + void deferredResultSubscriberWithOneValue() throws Exception { // Mono Sinks.One sink = Sinks.one(); @@ -178,7 +177,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void deferredResultSubscriberWithNoValues() throws Exception { + void deferredResultSubscriberWithNoValues() throws Exception { Sinks.One sink = Sinks.one(); testDeferredResultSubscriber(sink.asMono(), Mono.class, forClass(String.class), () -> sink.emitEmpty(Sinks.EmitFailureHandler.FAIL_FAST), @@ -186,7 +185,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void deferredResultSubscriberWithMultipleValues() throws Exception { + void deferredResultSubscriberWithMultipleValues() throws Exception { // JSON must be preferred for Flux -> List or else we stream this.servletRequest.addHeader("Accept", "application/json"); @@ -203,7 +202,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void deferredResultSubscriberWithError() throws Exception { + void deferredResultSubscriberWithError() throws Exception { IllegalStateException ex = new IllegalStateException(); @@ -220,7 +219,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void mediaTypes() throws Exception { + void mediaTypes() throws Exception { // Media type from request this.servletRequest.addHeader("Accept", "text/event-stream"); @@ -243,7 +242,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void writeServerSentEvents() throws Exception { + void writeServerSentEvents() throws Exception { this.servletRequest.addHeader("Accept", "text/event-stream"); Sinks.Many sink = Sinks.many().unicast().onBackpressureBuffer(); @@ -261,7 +260,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void writeServerSentEventsWithBuilder() throws Exception { + void writeServerSentEventsWithBuilder() throws Exception { ResolvableType type = ResolvableType.forClassWithGenerics(ServerSentEvent.class, String.class); @@ -280,7 +279,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void writeStreamJson() throws Exception { + void writeStreamJson() throws Exception { this.servletRequest.addHeader("Accept", "application/x-ndjson"); @@ -305,7 +304,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void writeStreamJsonWithVendorSubtype() throws Exception { + void writeStreamJsonWithVendorSubtype() throws Exception { this.servletRequest.addHeader("Accept", "application/vnd.myapp.v1+x-ndjson"); Sinks.Many sink = Sinks.many().unicast().onBackpressureBuffer(); @@ -331,7 +330,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void writeStreamJsonWithWildcardSubtype() throws Exception { + void writeStreamJsonWithWildcardSubtype() throws Exception { this.servletRequest.addHeader("Accept", "application/*+x-ndjson"); Sinks.Many sink = Sinks.many().unicast().onBackpressureBuffer(); @@ -357,7 +356,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void writeText() throws Exception { + void writeText() throws Exception { Sinks.Many sink = Sinks.many().unicast().onBackpressureBuffer(); ResponseBodyEmitter emitter = handleValue(sink.asFlux(), Flux.class, forClass(String.class)); @@ -374,7 +373,7 @@ public class ReactiveTypeHandlerTests { } @Test - public void writeFluxOfString() throws Exception { + void writeFluxOfString() throws Exception { // Default to "text/plain" testEmitterContentType("text/plain"); @@ -462,12 +461,12 @@ public class ReactiveTypeHandlerTests { } @Override - public void send(Object data, MediaType mediaType) throws IOException { + public void send(Object data, MediaType mediaType) { this.values.add(data); } @Override - public void send(Set items) throws IOException { + public void send(Set items) { items.forEach(item -> this.values.add(item.getData())); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestAttributeMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestAttributeMethodArgumentResolverTests.java index 66b0f6bbd1e..cd2550bd08c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestAttributeMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestAttributeMethodArgumentResolverTests.java @@ -25,7 +25,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; * @author Rossen Stoyanchev * @since 4.3 */ -public class RequestAttributeMethodArgumentResolverTests extends AbstractRequestAttributesArgumentResolverTests { +class RequestAttributeMethodArgumentResolverTests extends AbstractRequestAttributesArgumentResolverTests { @Override protected HandlerMethodArgumentResolver createResolver() { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterIntegrationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterIntegrationTests.java index 9a0d1a4f099..eb7db9e719c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterIntegrationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,6 +23,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Method; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.security.Principal; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -162,7 +163,7 @@ class RequestMappingHandlerAdapterIntegrationTests { request.addParameter("paramByConvention", "paramByConventionValue"); request.addParameter("age", "25"); request.setCookies(new Cookie("cookie", "99")); - request.setContent("Hello World".getBytes("UTF-8")); + request.setContent("Hello World".getBytes(StandardCharsets.UTF_8)); request.setUserPrincipal(new User()); request.setContextPath("/contextPath"); request.setServletPath("/main"); @@ -244,7 +245,7 @@ class RequestMappingHandlerAdapterIntegrationTests { request.addParameter("paramByConvention", "paramByConventionValue"); request.addParameter("age", "25"); request.setCookies(new Cookie("cookie", "99")); - request.setContent("Hello World".getBytes("UTF-8")); + request.setContent("Hello World".getBytes(StandardCharsets.UTF_8)); request.setUserPrincipal(new User()); request.setContextPath("/contextPath"); request.setServletPath("/main"); @@ -310,14 +311,14 @@ class RequestMappingHandlerAdapterIntegrationTests { request.setMethod("POST"); request.addHeader("Content-Type", "text/plain; charset=utf-8"); - request.setContent("Hello Server".getBytes("UTF-8")); + request.setContent("Hello Server".getBytes(StandardCharsets.UTF_8)); HandlerMethod handlerMethod = handlerMethod("handleRequestBody", parameterTypes); ModelAndView mav = handlerAdapter.handle(request, response, handlerMethod); assertThat(mav).isNull(); - assertThat(new String(response.getContentAsByteArray(), "UTF-8")).isEqualTo("Handled requestBody=[Hello Server]"); + assertThat(new String(response.getContentAsByteArray(), StandardCharsets.UTF_8)).isEqualTo("Handled requestBody=[Hello Server]"); assertThat(response.getStatus()).isEqualTo(HttpStatus.ACCEPTED.value()); } @@ -326,14 +327,14 @@ class RequestMappingHandlerAdapterIntegrationTests { Class[] parameterTypes = new Class[] {TestBean.class, Errors.class}; request.addHeader("Content-Type", "text/plain; charset=utf-8"); - request.setContent("Hello Server".getBytes("UTF-8")); + request.setContent("Hello Server".getBytes(StandardCharsets.UTF_8)); HandlerMethod handlerMethod = handlerMethod("handleAndValidateRequestBody", parameterTypes); ModelAndView mav = handlerAdapter.handle(request, response, handlerMethod); assertThat(mav).isNull(); - assertThat(new String(response.getContentAsByteArray(), "UTF-8")).isEqualTo("Error count [1]"); + assertThat(new String(response.getContentAsByteArray(), StandardCharsets.UTF_8)).isEqualTo("Error count [1]"); assertThat(response.getStatus()).isEqualTo(HttpStatus.ACCEPTED.value()); } @@ -342,7 +343,7 @@ class RequestMappingHandlerAdapterIntegrationTests { Class[] parameterTypes = new Class[] {HttpEntity.class}; request.addHeader("Content-Type", "text/plain; charset=utf-8"); - request.setContent("Hello Server".getBytes("UTF-8")); + request.setContent("Hello Server".getBytes(StandardCharsets.UTF_8)); HandlerMethod handlerMethod = handlerMethod("handleHttpEntity", parameterTypes); @@ -350,7 +351,7 @@ class RequestMappingHandlerAdapterIntegrationTests { assertThat(mav).isNull(); assertThat(response.getStatus()).isEqualTo(HttpStatus.ACCEPTED.value()); - assertThat(new String(response.getContentAsByteArray(), "UTF-8")).isEqualTo("Handled requestBody=[Hello Server]"); + assertThat(new String(response.getContentAsByteArray(), StandardCharsets.UTF_8)).isEqualTo("Handled requestBody=[Hello Server]"); assertThat(response.getHeader("header")).isEqualTo("headerValue"); // set because of @SessionAttributes assertThat(response.getHeader("Cache-Control")).isEqualTo("no-store"); @@ -361,21 +362,21 @@ class RequestMappingHandlerAdapterIntegrationTests { void handleHttpEntityWithCacheControl() throws Exception { Class[] parameterTypes = new Class[] {HttpEntity.class}; request.addHeader("Content-Type", "text/plain; charset=utf-8"); - request.setContent("Hello Server".getBytes("UTF-8")); + request.setContent("Hello Server".getBytes(StandardCharsets.UTF_8)); HandlerMethod handlerMethod = handlerMethod("handleHttpEntityWithCacheControl", parameterTypes); ModelAndView mav = handlerAdapter.handle(request, response, handlerMethod); assertThat(mav).isNull(); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); - assertThat(new String(response.getContentAsByteArray(), "UTF-8")).isEqualTo("Handled requestBody=[Hello Server]"); + assertThat(new String(response.getContentAsByteArray(), StandardCharsets.UTF_8)).isEqualTo("Handled requestBody=[Hello Server]"); assertThat(response.getHeaderValues("Cache-Control")).containsExactly("max-age=3600"); } @Test void handleRequestPart() throws Exception { MockMultipartHttpServletRequest multipartRequest = new MockMultipartHttpServletRequest(); - multipartRequest.addFile(new MockMultipartFile("requestPart", "", "text/plain", "content".getBytes("UTF-8"))); + multipartRequest.addFile(new MockMultipartFile("requestPart", "", "text/plain", "content".getBytes(StandardCharsets.UTF_8))); HandlerMethod handlerMethod = handlerMethod("handleRequestPart", String.class, Model.class); ModelAndView mav = handlerAdapter.handle(multipartRequest, response, handlerMethod); @@ -387,7 +388,7 @@ class RequestMappingHandlerAdapterIntegrationTests { @Test void handleAndValidateRequestPart() throws Exception { MockMultipartHttpServletRequest multipartRequest = new MockMultipartHttpServletRequest(); - multipartRequest.addFile(new MockMultipartFile("requestPart", "", "text/plain", "content".getBytes("UTF-8"))); + multipartRequest.addFile(new MockMultipartFile("requestPart", "", "text/plain", "content".getBytes(StandardCharsets.UTF_8))); HandlerMethod handlerMethod = handlerMethod("handleAndValidateRequestPart", String.class, Errors.class, Model.class); ModelAndView mav = handlerAdapter.handle(multipartRequest, response, handlerMethod); @@ -552,8 +553,8 @@ class RequestMappingHandlerAdapterIntegrationTests { @ResponseStatus(HttpStatus.ACCEPTED) @ResponseBody - public String handleRequestBody(@RequestBody byte[] bytes) throws Exception { - String requestBody = new String(bytes, "UTF-8"); + public String handleRequestBody(@RequestBody byte[] bytes) { + String requestBody = new String(bytes, StandardCharsets.UTF_8); return "Handled requestBody=[" + requestBody + "]"; } @@ -563,15 +564,15 @@ class RequestMappingHandlerAdapterIntegrationTests { return "Error count [" + errors.getErrorCount() + "]"; } - public ResponseEntity handleHttpEntity(HttpEntity httpEntity) throws Exception { - String responseBody = "Handled requestBody=[" + new String(httpEntity.getBody(), "UTF-8") + "]"; + public ResponseEntity handleHttpEntity(HttpEntity httpEntity) { + String responseBody = "Handled requestBody=[" + new String(httpEntity.getBody(), StandardCharsets.UTF_8) + "]"; return ResponseEntity.accepted() .header("header", "headerValue") .body(responseBody); } - public ResponseEntity handleHttpEntityWithCacheControl(HttpEntity httpEntity) throws Exception { - String responseBody = "Handled requestBody=[" + new String(httpEntity.getBody(), "UTF-8") + "]"; + public ResponseEntity handleHttpEntityWithCacheControl(HttpEntity httpEntity) { + String responseBody = "Handled requestBody=[" + new String(httpEntity.getBody(), StandardCharsets.UTF_8) + "]"; return ResponseEntity.ok().cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)).body(responseBody); } @@ -580,7 +581,7 @@ class RequestMappingHandlerAdapterIntegrationTests { } public void handleAndValidateRequestPart(@RequestPart @Valid String requestPart, - Errors errors, Model model) throws Exception { + Errors errors, Model model) { model.addAttribute("error count", errors.getErrorCount()); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterTests.java index 4fc2c5fe788..c8f549fdff0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapterTests.java @@ -72,7 +72,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @see HandlerMethodAnnotationDetectionTests * @see RequestMappingHandlerAdapterIntegrationTests */ -public class RequestMappingHandlerAdapterTests { +class RequestMappingHandlerAdapterTests { private static int RESOLVER_COUNT; @@ -101,7 +101,7 @@ public class RequestMappingHandlerAdapterTests { } @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { this.webAppContext = new StaticWebApplicationContext(); this.handlerAdapter = new RequestMappingHandlerAdapter(); this.handlerAdapter.setApplicationContext(this.webAppContext); @@ -111,7 +111,7 @@ public class RequestMappingHandlerAdapterTests { @Test - public void cacheControlWithoutSessionAttributes() throws Exception { + void cacheControlWithoutSessionAttributes() throws Exception { HandlerMethod handlerMethod = handlerMethod(new TestController(), "handle"); this.handlerAdapter.setCacheSeconds(100); this.handlerAdapter.afterPropertiesSet(); @@ -121,7 +121,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void cacheControlWithSessionAttributes() throws Exception { + void cacheControlWithSessionAttributes() throws Exception { SessionAttributeController handler = new SessionAttributeController(); this.handlerAdapter.setCacheSeconds(100); this.handlerAdapter.afterPropertiesSet(); @@ -131,7 +131,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void setAlwaysUseRedirectAttributes() throws Exception { + void setAlwaysUseRedirectAttributes() throws Exception { HandlerMethodArgumentResolver redirectAttributesResolver = new RedirectAttributesMethodArgumentResolver(); HandlerMethodArgumentResolver modelResolver = new ModelMethodProcessor(); HandlerMethodReturnValueHandler viewHandler = new ViewNameMethodReturnValueHandler(); @@ -149,7 +149,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void setCustomArgumentResolvers() throws Exception { + void setCustomArgumentResolvers() throws Exception { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.handlerAdapter.setCustomArgumentResolvers(Collections.singletonList(resolver)); this.handlerAdapter.afterPropertiesSet(); @@ -159,7 +159,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void setArgumentResolvers() throws Exception { + void setArgumentResolvers() throws Exception { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.handlerAdapter.setArgumentResolvers(Collections.singletonList(resolver)); this.handlerAdapter.afterPropertiesSet(); @@ -168,7 +168,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void setInitBinderArgumentResolvers() throws Exception { + void setInitBinderArgumentResolvers() throws Exception { HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver(); this.handlerAdapter.setInitBinderArgumentResolvers(Collections.singletonList(resolver)); this.handlerAdapter.afterPropertiesSet(); @@ -177,7 +177,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void setCustomReturnValueHandlers() { + void setCustomReturnValueHandlers() { HandlerMethodReturnValueHandler handler = new ViewNameMethodReturnValueHandler(); this.handlerAdapter.setCustomReturnValueHandlers(Collections.singletonList(handler)); this.handlerAdapter.afterPropertiesSet(); @@ -187,7 +187,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void setReturnValueHandlers() { + void setReturnValueHandlers() { HandlerMethodReturnValueHandler handler = new ModelMethodProcessor(); this.handlerAdapter.setReturnValueHandlers(Collections.singletonList(handler)); this.handlerAdapter.afterPropertiesSet(); @@ -196,7 +196,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void modelAttributeAdvice() throws Exception { + void modelAttributeAdvice() throws Exception { this.webAppContext.registerSingleton("maa", ModelAttributeAdvice.class); this.webAppContext.refresh(); @@ -209,7 +209,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void prototypeControllerAdvice() throws Exception { + void prototypeControllerAdvice() throws Exception { this.webAppContext.registerPrototype("maa", ModelAttributeAdvice.class); this.webAppContext.refresh(); @@ -222,7 +222,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void modelAttributeAdviceInParentContext() throws Exception { + void modelAttributeAdviceInParentContext() throws Exception { StaticWebApplicationContext parent = new StaticWebApplicationContext(); parent.registerSingleton("maa", ModelAttributeAdvice.class); parent.refresh(); @@ -238,7 +238,7 @@ public class RequestMappingHandlerAdapterTests { } @Test - public void modelAttributePackageNameAdvice() throws Exception { + void modelAttributePackageNameAdvice() throws Exception { this.webAppContext.registerSingleton("mapa", ModelAttributePackageAdvice.class); this.webAppContext.registerSingleton("manupa", ModelAttributeNotUsedPackageAdvice.class); this.webAppContext.refresh(); 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 bb79daad388..b960fa98ac0 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -68,7 +68,7 @@ import static org.mockito.Mockito.mock; * @author Sam Brannen * @author Olga Maciaszek-Sharma */ -public class RequestMappingHandlerMappingTests { +class RequestMappingHandlerMappingTests { @SuppressWarnings("unused") static Stream pathPatternsArguments() { @@ -353,12 +353,10 @@ public class RequestMappingHandlerMappingTests { assertThat(info).isNotNull(); Set paths = info.getPatternValues(); - assertThat(paths).hasSize(1); - assertThat(paths).element(0).isEqualTo(path); + assertThat(paths).containsExactly(path); Set methods = info.getMethodsCondition().getMethods(); - assertThat(methods).hasSize(1); - assertThat(methods).element(0).isEqualTo(requestMethod); + assertThat(methods).containsExactly(requestMethod); return info; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java index 0f385345f29..6502e195ea8 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -144,13 +144,13 @@ class RequestPartIntegrationTests { @Test - void standardMultipartResolver() throws Exception { + void standardMultipartResolver() { testCreate(baseUrl + "/standard-resolver/test", "Jason"); testCreate(baseUrl + "/standard-resolver/test", "Arjen"); } @Test // SPR-13319 - void standardMultipartResolverWithEncodedFileName() throws Exception { + void standardMultipartResolverWithEncodedFileName() { String boundaryText = MimeTypeUtils.generateMultipartBoundaryString(); Map params = Collections.singletonMap("boundary", boundaryText); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java index 0b015a5aa6d..ad69f535640 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,7 +77,6 @@ import static org.mockito.Mockito.reset; */ class RequestPartMethodArgumentResolverTests { - @SuppressWarnings("unchecked") private HttpMessageConverter messageConverter = mock(); private RequestPartMethodArgumentResolver resolver; @@ -290,7 +289,7 @@ class RequestPartMethodArgumentResolverTests { } @Test - void resolveRequestPartNotValid() throws Exception { + void resolveRequestPartNotValid() { assertThatExceptionOfType(MethodArgumentNotValidException.class).isThrownBy(() -> testResolveArgument(new SimpleBean(null), paramValidRequestPart)) .satisfies(ex -> { @@ -307,7 +306,7 @@ class RequestPartMethodArgumentResolverTests { } @Test - void resolveRequestPartRequired() throws Exception { + void resolveRequestPartRequired() { assertThatExceptionOfType(MissingServletRequestPartException.class).isThrownBy(() -> testResolveArgument(null, paramValidRequestPart)) .satisfies(ex -> assertThat(ex.getRequestPartName()).isEqualTo("requestPart")); @@ -335,7 +334,7 @@ class RequestPartMethodArgumentResolverTests { } @Test - void isMultipartRequest() throws Exception { + void isMultipartRequest() { MockHttpServletRequest request = new MockHttpServletRequest(); assertThatExceptionOfType(MultipartException.class).isThrownBy(() -> resolver.resolveArgument(paramMultipartFile, new ModelAndViewContainer(), new ServletWebRequest(request), null)); @@ -596,7 +595,7 @@ class RequestPartMethodArgumentResolverTests { @Override public WebDataBinder createBinder(NativeWebRequest webRequest, @Nullable Object target, - String objectName) throws Exception { + String objectName) { LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean(); validator.afterPropertiesSet(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChainTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChainTests.java index 8caabb12ae1..0c95016571a 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChainTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChainTests.java @@ -68,7 +68,6 @@ class RequestResponseBodyAdviceChainTests { @Test - @SuppressWarnings("unchecked") void requestBodyAdvice() throws IOException { RequestBodyAdvice requestAdvice = mock(); ResponseBodyAdvice responseAdvice = mock(); @@ -91,7 +90,6 @@ class RequestResponseBodyAdviceChainTests { } @Test - @SuppressWarnings("unchecked") void responseBodyAdvice() { RequestBodyAdvice requestAdvice = mock(); ResponseBodyAdvice responseAdvice = mock(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorMockTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorMockTests.java index df9fc6a155b..d1c3cf2edba 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorMockTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorMockTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -80,13 +80,10 @@ import static org.mockito.Mockito.verify; */ class RequestResponseBodyMethodProcessorMockTests { - @SuppressWarnings("unchecked") private HttpMessageConverter stringMessageConverter = mock(); - @SuppressWarnings("unchecked") private HttpMessageConverter resourceMessageConverter = mock(); - @SuppressWarnings("unchecked") private HttpMessageConverter resourceRegionMessageConverter = mock(); private RequestResponseBodyMethodProcessor processor; @@ -111,7 +108,6 @@ class RequestResponseBodyMethodProcessorMockTests { @BeforeEach - @SuppressWarnings("unchecked") void setup() throws Exception { given(stringMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN)); given(stringMessageConverter.getSupportedMediaTypes(any())).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN)); @@ -168,7 +164,7 @@ class RequestResponseBodyMethodProcessorMockTests { } @Test - void resolveArgumentNotValid() throws Exception { + void resolveArgumentNotValid() { assertThatExceptionOfType(MethodArgumentNotValidException.class).isThrownBy(() -> testResolveArgumentWithValidation(new SimpleBean(null))) .satisfies(ex -> { @@ -200,7 +196,7 @@ class RequestResponseBodyMethodProcessorMockTests { } @Test - void resolveArgumentCannotRead() throws Exception { + void resolveArgumentCannotRead() { MediaType contentType = MediaType.TEXT_PLAIN; servletRequest.addHeader("Content-Type", contentType.toString()); servletRequest.setContent("payload".getBytes(StandardCharsets.UTF_8)); @@ -212,7 +208,7 @@ class RequestResponseBodyMethodProcessorMockTests { } @Test - void resolveArgumentNoContentType() throws Exception { + void resolveArgumentNoContentType() { servletRequest.setContent("payload".getBytes(StandardCharsets.UTF_8)); given(stringMessageConverter.canRead(String.class, MediaType.APPLICATION_OCTET_STREAM)).willReturn(false); assertThatExceptionOfType(HttpMediaTypeNotSupportedException.class).isThrownBy(() -> @@ -220,7 +216,7 @@ class RequestResponseBodyMethodProcessorMockTests { } @Test - void resolveArgumentInvalidContentType() throws Exception { + void resolveArgumentInvalidContentType() { this.servletRequest.setContentType("bad"); servletRequest.setContent("payload".getBytes(StandardCharsets.UTF_8)); assertThatExceptionOfType(HttpMediaTypeNotSupportedException.class).isThrownBy(() -> @@ -336,12 +332,12 @@ class RequestResponseBodyMethodProcessorMockTests { @Test - void handleReturnValueNotAcceptable() throws Exception { + void handleReturnValueNotAcceptable() { MediaType accepted = MediaType.APPLICATION_ATOM_XML; servletRequest.addHeader("Accept", accepted.toString()); given(stringMessageConverter.canWrite(String.class, null)).willReturn(true); - given(stringMessageConverter.getSupportedMediaTypes()).willReturn(Arrays.asList(MediaType.TEXT_PLAIN)); + given(stringMessageConverter.getSupportedMediaTypes()).willReturn(List.of(MediaType.TEXT_PLAIN)); given(stringMessageConverter.canWrite(String.class, accepted)).willReturn(false); assertThatExceptionOfType(HttpMediaTypeNotAcceptableException.class).isThrownBy(() -> @@ -349,7 +345,7 @@ class RequestResponseBodyMethodProcessorMockTests { } @Test - void handleReturnValueNotAcceptableProduces() throws Exception { + void handleReturnValueNotAcceptableProduces() { MediaType accepted = MediaType.TEXT_PLAIN; servletRequest.addHeader("Accept", accepted.toString()); @@ -467,7 +463,7 @@ class RequestResponseBodyMethodProcessorMockTests { @Override public WebDataBinder createBinder(NativeWebRequest webRequest, @Nullable Object target, - String objectName) throws Exception { + String objectName) { LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean(); validator.afterPropertiesSet(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java index c186111642a..fa743061910 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandlerTests.java @@ -83,7 +83,7 @@ import static org.mockito.BDDMockito.mock; * @author Sebastien Deleuze * @author Yanming Zhou */ -public class ResponseEntityExceptionHandlerTests { +class ResponseEntityExceptionHandlerTests { private final ResponseEntityExceptionHandler exceptionHandler = new ApplicationExceptionHandler(); @@ -98,7 +98,7 @@ public class ResponseEntityExceptionHandlerTests { @SuppressWarnings("unchecked") @Test - public void supportsAllDefaultHandlerExceptionResolverExceptionTypes() throws Exception { + void supportsAllDefaultHandlerExceptionResolverExceptionTypes() throws Exception { ExceptionHandler annotation = ResponseEntityExceptionHandler.class .getMethod("handleException", Exception.class, WebRequest.class) @@ -114,7 +114,7 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void httpRequestMethodNotSupported() { + void httpRequestMethodNotSupported() { ResponseEntity entity = testException(new HttpRequestMethodNotSupportedException("GET", List.of("POST", "DELETE"))); @@ -122,7 +122,7 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void httpMediaTypeNotSupported() { + void httpMediaTypeNotSupported() { ResponseEntity entity = testException(new HttpMediaTypeNotSupportedException( MediaType.APPLICATION_JSON, List.of(MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_XML))); @@ -131,7 +131,7 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void patchHttpMediaTypeNotSupported() { + void patchHttpMediaTypeNotSupported() { this.servletRequest = new MockHttpServletRequest("PATCH", "/"); this.request = new ServletWebRequest(this.servletRequest, this.servletResponse); @@ -148,28 +148,28 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void httpMediaTypeNotAcceptable() { + void httpMediaTypeNotAcceptable() { testException(new HttpMediaTypeNotAcceptableException("")); } @Test - public void missingPathVariable() throws NoSuchMethodException { + void missingPathVariable() throws NoSuchMethodException { testException(new MissingPathVariableException("param", new MethodParameter(getClass().getDeclaredMethod("handle", String.class), 0))); } @Test - public void missingServletRequestParameter() { + void missingServletRequestParameter() { testException(new MissingServletRequestParameterException("param", "type")); } @Test - public void servletRequestBindingException() { + void servletRequestBindingException() { testException(new ServletRequestBindingException("message")); } @Test - public void errorResponseProblemDetailViaMessageSource() { + void errorResponseProblemDetailViaMessageSource() { try { Locale locale = Locale.UK; LocaleContextHolder.setLocale(locale); @@ -226,17 +226,17 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void conversionNotSupported() { + void conversionNotSupported() { testException(new ConversionNotSupportedException(new Object(), Object.class, null)); } @Test - public void typeMismatch() { + void typeMismatch() { testException(new TypeMismatchException("foo", String.class)); } @Test - public void typeMismatchWithProblemDetailViaMessageSource() { + void typeMismatchWithProblemDetailViaMessageSource() { Locale locale = Locale.UK; LocaleContextHolder.setLocale(locale); @@ -266,39 +266,39 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void httpMessageNotWritable() { + void httpMessageNotWritable() { testException(new HttpMessageNotWritableException("")); } @Test - public void methodArgumentNotValid() throws Exception { + void methodArgumentNotValid() throws Exception { testException(new MethodArgumentNotValidException( new MethodParameter(getClass().getDeclaredMethod("handle", String.class), 0), new MapBindingResult(Collections.emptyMap(), "name"))); } @Test - public void handlerMethodValidationException() { + void handlerMethodValidationException() { testException(new HandlerMethodValidationException(mock(MethodValidationResult.class))); } @Test - public void methodValidationException() { + void methodValidationException() { testException(new MethodValidationException(mock(MethodValidationResult.class))); } @Test - public void missingServletRequestPart() { + void missingServletRequestPart() { testException(new MissingServletRequestPartException("partName")); } @Test - public void bindException() { + void bindException() { testException(new BindException(new Object(), "name")); } @Test - public void noHandlerFoundException() { + void noHandlerFoundException() { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); // gh-29626 @@ -309,17 +309,17 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void noResourceFoundException() { + void noResourceFoundException() { testException(new NoResourceFoundException(HttpMethod.GET, "/resource")); } @Test - public void asyncRequestTimeoutException() { + void asyncRequestTimeoutException() { testException(new AsyncRequestTimeoutException()); } @Test - public void maxUploadSizeExceededException() { + void maxUploadSizeExceededException() { testException(new MaxUploadSizeExceededException(1000)); } @@ -333,7 +333,7 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void controllerAdvice() throws Exception { + void controllerAdvice() throws Exception { StaticWebApplicationContext ctx = new StaticWebApplicationContext(); ctx.registerSingleton("exceptionHandler", ApplicationExceptionHandler.class); ctx.refresh(); @@ -351,7 +351,7 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void controllerAdviceWithNestedException() { + void controllerAdviceWithNestedException() { StaticWebApplicationContext ctx = new StaticWebApplicationContext(); ctx.registerSingleton("exceptionHandler", ApplicationExceptionHandler.class); ctx.refresh(); @@ -368,7 +368,7 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void controllerAdviceWithinDispatcherServlet() throws Exception { + void controllerAdviceWithinDispatcherServlet() throws Exception { StaticWebApplicationContext ctx = new StaticWebApplicationContext(); ctx.registerSingleton("controller", ExceptionThrowingController.class); ctx.registerSingleton("exceptionHandler", ApplicationExceptionHandler.class); @@ -384,7 +384,7 @@ public class ResponseEntityExceptionHandlerTests { } @Test - public void controllerAdviceWithNestedExceptionWithinDispatcherServlet() throws Exception { + void controllerAdviceWithNestedExceptionWithinDispatcherServlet() throws Exception { StaticWebApplicationContext ctx = new StaticWebApplicationContext(); ctx.registerSingleton("controller", NestedExceptionThrowingController.class); ctx.registerSingleton("exceptionHandler", ApplicationExceptionHandler.class); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java index a1f93d7d89e..7d0d218c044 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -2782,7 +2782,7 @@ class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandl model.put("myKey", "myOriginalValue"); ValidTestBean tb = new ValidTestBean(); - tb.setName(defaultName.getClass().getSimpleName() + ":" + defaultName.toString()); + tb.setName(defaultName.getClass().getSimpleName() + ":" + defaultName); return tb; } @@ -3054,40 +3054,35 @@ class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandl @Override public View resolveViewName(final String viewName, Locale locale) throws Exception { - return new View() { - @Override - @SuppressWarnings({"unchecked", "deprecation", "rawtypes"}) - public void render(@Nullable Map model, HttpServletRequest request, HttpServletResponse response) - throws Exception { - TestBean tb = (TestBean) model.get("testBean"); - if (tb == null) { - tb = (TestBean) model.get("myCommand"); - } - if (tb.getName() != null && tb.getName().endsWith("myDefaultName")) { - assertThat(tb.getDate().getYear()).isEqualTo(107); - } - Errors errors = (Errors) model.get(BindingResult.MODEL_KEY_PREFIX + "testBean"); - if (errors == null) { - errors = (Errors) model.get(BindingResult.MODEL_KEY_PREFIX + "myCommand"); - } - if (errors.hasFieldErrors("date")) { - throw new IllegalStateException(); - } - if (model.containsKey("ITestBean")) { - boolean condition = model.get(BindingResult.MODEL_KEY_PREFIX + "ITestBean") instanceof Errors; - assertThat(condition).isTrue(); - } - List testBeans = (List) model.get("testBeanList"); - if (errors.hasFieldErrors("age")) { - response.getWriter() - .write(viewName + "-" + tb.getName() + "-" + errors.getFieldError("age").getCode() + - "-" + testBeans.get(0).getName() + "-" + model.get("myKey") + - (model.containsKey("yourKey") ? "-" + model.get("yourKey") : "")); - } - else { - response.getWriter().write(viewName + "-" + tb.getName() + "-" + tb.getAge() + "-" + - errors.getFieldValue("name") + "-" + errors.getFieldValue("age")); - } + return (model, request, response) -> { + TestBean tb = (TestBean) model.get("testBean"); + if (tb == null) { + tb = (TestBean) model.get("myCommand"); + } + if (tb.getName() != null && tb.getName().endsWith("myDefaultName")) { + assertThat(tb.getDate().getYear()).isEqualTo(107); + } + Errors errors = (Errors) model.get(BindingResult.MODEL_KEY_PREFIX + "testBean"); + if (errors == null) { + errors = (Errors) model.get(BindingResult.MODEL_KEY_PREFIX + "myCommand"); + } + if (errors.hasFieldErrors("date")) { + throw new IllegalStateException(); + } + if (model.containsKey("ITestBean")) { + boolean condition = model.get(BindingResult.MODEL_KEY_PREFIX + "ITestBean") instanceof Errors; + assertThat(condition).isTrue(); + } + List testBeans = (List) model.get("testBeanList"); + if (errors.hasFieldErrors("age")) { + response.getWriter() + .write(viewName + "-" + tb.getName() + "-" + errors.getFieldError("age").getCode() + + "-" + testBeans.get(0).getName() + "-" + model.get("myKey") + + (model.containsKey("yourKey") ? "-" + model.get("yourKey") : "")); + } + else { + response.getWriter().write(viewName + "-" + tb.getName() + "-" + tb.getAge() + "-" + + errors.getFieldValue("name") + "-" + errors.getFieldValue("age")); } }; } @@ -3171,7 +3166,7 @@ class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandl @RequestParam(required = false) boolean flag, @RequestHeader(value = "header", required = false) String header, HttpServletResponse response) throws IOException { - response.getWriter().write(String.valueOf(id) + "-" + flag + "-" + String.valueOf(header)); + response.getWriter().write(id + "-" + flag + "-" + header); } } @@ -3183,7 +3178,7 @@ class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandl @RequestParam(value = "otherId", defaultValue = "") String id2, @RequestHeader(defaultValue = "bar") String header, HttpServletResponse response) throws IOException { - response.getWriter().write(String.valueOf(id) + "-" + String.valueOf(id2) + "-" + String.valueOf(header)); + response.getWriter().write(id + "-" + id2 + "-" + header); } } @@ -3195,7 +3190,7 @@ class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandl @RequestHeader(defaultValue = "#{systemProperties.myHeader}") String header, @Value("#{request.contextPath}") String contextPath, HttpServletResponse response) throws IOException { - response.getWriter().write(String.valueOf(id) + "-" + String.valueOf(header) + "-" + contextPath); + response.getWriter().write(id + "-" + header + "-" + contextPath); } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java index d6847d7e8ed..dc0f510a02e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Arjen Poutsma * @author Rossen Stoyanchev */ -public class ServletCookieValueMethodArgumentResolverTests { +class ServletCookieValueMethodArgumentResolverTests { private ServletCookieValueMethodArgumentResolver resolver; @@ -50,7 +50,7 @@ public class ServletCookieValueMethodArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { resolver = new ServletCookieValueMethodArgumentResolver(null); request = new MockHttpServletRequest(); webRequest = new ServletWebRequest(request, new MockHttpServletResponse()); @@ -62,7 +62,7 @@ public class ServletCookieValueMethodArgumentResolverTests { @Test - public void resolveCookieArgument() throws Exception { + void resolveCookieArgument() throws Exception { Cookie expected = new Cookie("name", "foo"); request.setCookies(expected); @@ -71,7 +71,7 @@ public class ServletCookieValueMethodArgumentResolverTests { } @Test - public void resolveCookieStringArgument() throws Exception { + void resolveCookieStringArgument() throws Exception { Cookie cookie = new Cookie("name", "foo"); request.setCookies(cookie); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethodTests.java index d079de3e66b..03ac4e60fff 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethodTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -71,7 +71,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Sam Brannen * @author Juergen Hoeller */ -public class ServletInvocableHandlerMethodTests { +class ServletInvocableHandlerMethodTests { private final List> converters = Collections.singletonList(new StringHttpMessageConverter()); @@ -92,7 +92,7 @@ public class ServletInvocableHandlerMethodTests { @Test - public void invokeAndHandle_VoidWithResponseStatus() throws Exception { + void invokeAndHandle_VoidWithResponseStatus() throws Exception { ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "responseStatus"); handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer); @@ -103,7 +103,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void invokeAndHandle_VoidWithComposedResponseStatus() throws Exception { + void invokeAndHandle_VoidWithComposedResponseStatus() throws Exception { ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "composedResponseStatus"); handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer); @@ -114,7 +114,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void invokeAndHandle_VoidWithTypeLevelResponseStatus() throws Exception { + void invokeAndHandle_VoidWithTypeLevelResponseStatus() throws Exception { ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseStatusHandler(), "handle"); handlerMethod.invokeAndHandle(this.webRequest, this.mavContainer); @@ -123,7 +123,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void invokeAndHandle_VoidWithHttpServletResponseArgument() throws Exception { + void invokeAndHandle_VoidWithHttpServletResponseArgument() throws Exception { this.argumentResolvers.addResolver(new ServletResponseMethodArgumentResolver()); ServletInvocableHandlerMethod handlerMethod = @@ -136,7 +136,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void invokeAndHandle_VoidRequestNotModified() throws Exception { + void invokeAndHandle_VoidRequestNotModified() throws Exception { this.request.addHeader("If-Modified-Since", 10 * 1000 * 1000); int lastModifiedTimestamp = 1000 * 1000; this.webRequest.checkNotModified(lastModifiedTimestamp); @@ -150,7 +150,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void invokeAndHandle_VoidNotModifiedWithEtag() throws Exception { + void invokeAndHandle_VoidNotModifiedWithEtag() throws Exception { String eTagValue = "\"deadb33f8badf00d\""; @@ -186,7 +186,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void invokeAndHandle_responseStatusAndReasonCode() throws Exception { + void invokeAndHandle_responseStatusAndReasonCode() throws Exception { Locale locale = Locale.ENGLISH; String beanName = "handler"; @@ -243,7 +243,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void invokeAndHandle_Exception() throws Exception { + void invokeAndHandle_Exception() throws Exception { this.returnValueHandlers.addHandler(new ExceptionRaisingReturnValueHandler()); ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new Handler(), "handle"); @@ -252,7 +252,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void invokeAndHandle_DynamicReturnValue() throws Exception { + void invokeAndHandle_DynamicReturnValue() throws Exception { this.argumentResolvers.addResolver(new RequestParamMethodArgumentResolver(null, false)); this.returnValueHandlers.addHandler(new ViewMethodReturnValueHandler()); this.returnValueHandlers.addHandler(new ViewNameMethodReturnValueHandler()); @@ -272,32 +272,32 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void wrapConcurrentResult_MethodLevelResponseBody() throws Exception { + void wrapConcurrentResult_MethodLevelResponseBody() throws Exception { wrapConcurrentResult_ResponseBody(new MethodLevelResponseBodyHandler(), "bar", String.class); } @Test - public void wrapConcurrentResult_MethodLevelResponseBodyEmpty() throws Exception { + void wrapConcurrentResult_MethodLevelResponseBodyEmpty() throws Exception { wrapConcurrentResult_ResponseBody(new MethodLevelResponseBodyHandler(), null, String.class); } @Test - public void wrapConcurrentResult_TypeLevelResponseBody() throws Exception { + void wrapConcurrentResult_TypeLevelResponseBody() throws Exception { wrapConcurrentResult_ResponseBody(new TypeLevelResponseBodyHandler(), "bar", String.class); } @Test - public void wrapConcurrentResult_TypeLevelResponseBodyEmpty() throws Exception { + void wrapConcurrentResult_TypeLevelResponseBodyEmpty() throws Exception { wrapConcurrentResult_ResponseBody(new TypeLevelResponseBodyHandler(), null, String.class); } @Test - public void wrapConcurrentResult_DeferredResultSubclass() throws Exception { + void wrapConcurrentResult_DeferredResultSubclass() throws Exception { wrapConcurrentResult_ResponseBody(new DeferredResultSubclassHandler(), "bar", String.class); } @Test - public void wrapConcurrentResult_DeferredResultSubclassEmpty() throws Exception { + void wrapConcurrentResult_DeferredResultSubclassEmpty() throws Exception { wrapConcurrentResult_ResponseBody(new DeferredResultSubclassHandler(), null, CustomDeferredResult.class); } @@ -316,7 +316,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void wrapConcurrentResult_ResponseEntity() throws Exception { + void wrapConcurrentResult_ResponseEntity() throws Exception { this.returnValueHandlers.addHandler(new HttpEntityMethodProcessor(this.converters)); ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseEntityHandler(), "handleDeferred"); handlerMethod = handlerMethod.wrapConcurrentResult(new ResponseEntity<>("bar", HttpStatus.OK)); @@ -337,7 +337,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void wrapConcurrentResult_ResponseEntityNullReturnValue() throws Exception { + void wrapConcurrentResult_ResponseEntityNullReturnValue() throws Exception { this.returnValueHandlers.addHandler(new HttpEntityMethodProcessor(this.converters)); ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new ResponseEntityHandler(), "handleDeferred"); handlerMethod = handlerMethod.wrapConcurrentResult(null); @@ -348,7 +348,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void wrapConcurrentResult_ResponseBodyEmitter() throws Exception { + void wrapConcurrentResult_ResponseBodyEmitter() throws Exception { this.returnValueHandlers.addHandler(new ResponseBodyEmitterReturnValueHandler(this.converters)); @@ -361,7 +361,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void wrapConcurrentResult_StreamingResponseBody() throws Exception { + void wrapConcurrentResult_StreamingResponseBody() throws Exception { this.returnValueHandlers.addHandler(new StreamingResponseBodyReturnValueHandler()); ServletInvocableHandlerMethod handlerMethod = getHandlerMethod(new StreamingHandler(), "handleStreamBody"); handlerMethod = handlerMethod.wrapConcurrentResult(null); @@ -372,7 +372,7 @@ public class ServletInvocableHandlerMethodTests { } @Test - public void wrapConcurrentResult_CollectedValuesList() throws Exception { + void wrapConcurrentResult_CollectedValuesList() throws Exception { List> converters = Collections.singletonList(new MappingJackson2HttpMessageConverter()); ResolvableType elementType = ResolvableType.forClass(List.class); ReactiveTypeHandler.CollectedValuesList result = new ReactiveTypeHandler.CollectedValuesList(elementType); @@ -535,7 +535,7 @@ public class ServletInvocableHandlerMethodTests { @Override public void handleReturnValue(Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { + ModelAndViewContainer mavContainer, NativeWebRequest webRequest) { throw new HttpMessageNotWritableException("oops, can't write"); } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessorTests.java index 354884106e5..a0ebaf38b76 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class ServletModelAttributeMethodProcessorTests { +class ServletModelAttributeMethodProcessorTests { private ServletModelAttributeMethodProcessor processor; @@ -62,7 +62,7 @@ public class ServletModelAttributeMethodProcessorTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { processor = new ServletModelAttributeMethodProcessor(false); ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); @@ -82,7 +82,7 @@ public class ServletModelAttributeMethodProcessorTests { @Test - public void createAttributeUriTemplateVar() throws Exception { + void createAttributeUriTemplateVar() throws Exception { Map uriTemplateVars = new HashMap<>(); uriTemplateVars.put("testBean1", "Patty"); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); @@ -95,7 +95,7 @@ public class ServletModelAttributeMethodProcessorTests { } @Test - public void createAttributeUriTemplateVarCannotConvert() throws Exception { + void createAttributeUriTemplateVarCannotConvert() throws Exception { Map uriTemplateVars = new HashMap<>(); uriTemplateVars.put("testBean2", "Patty"); request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars); @@ -121,7 +121,7 @@ public class ServletModelAttributeMethodProcessorTests { } @Test - public void createAttributeRequestParameter() throws Exception { + void createAttributeRequestParameter() throws Exception { request.addParameter("testBean1", "Patty"); // Type conversion from "Patty" to TestBean via TestBean(String) constructor @@ -132,7 +132,7 @@ public class ServletModelAttributeMethodProcessorTests { } @Test - public void createAttributeRequestParameterCannotConvert() throws Exception { + void createAttributeRequestParameterCannotConvert() throws Exception { request.addParameter("testBean2", "Patty"); TestBeanWithoutStringConstructor testBean = (TestBeanWithoutStringConstructor) processor.resolveArgument( diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java index 1db2214465c..fa591d7ccbe 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -55,7 +55,7 @@ import static org.mockito.Mockito.mock; * @author Juergen Hoeller * @author Nicholas Williams */ -public class ServletRequestMethodArgumentResolverTests { +class ServletRequestMethodArgumentResolverTests { private ServletRequestMethodArgumentResolver resolver; @@ -69,7 +69,7 @@ public class ServletRequestMethodArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { resolver = new ServletRequestMethodArgumentResolver(); mavContainer = new ModelAndViewContainer(); servletRequest = new MockHttpServletRequest("GET", ""); @@ -82,7 +82,7 @@ public class ServletRequestMethodArgumentResolverTests { @Test - public void servletRequest() throws Exception { + void servletRequest() throws Exception { MethodParameter servletRequestParameter = new MethodParameter(method, 0); assertThat(resolver.supportsParameter(servletRequestParameter)).as("ServletRequest not supported").isTrue(); @@ -92,7 +92,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void session() throws Exception { + void session() throws Exception { MockHttpSession session = new MockHttpSession(); servletRequest.setSession(session); @@ -105,7 +105,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void principal() throws Exception { + void principal() throws Exception { Principal principal = () -> "Foo"; servletRequest.setUserPrincipal(principal); @@ -117,7 +117,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void principalAsNull() throws Exception { + void principalAsNull() throws Exception { MethodParameter principalParameter = new MethodParameter(method, 3); assertThat(resolver.supportsParameter(principalParameter)).as("Principal not supported").isTrue(); @@ -136,7 +136,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void locale() throws Exception { + void locale() throws Exception { Locale locale = Locale.ENGLISH; servletRequest.addPreferredLocale(locale); @@ -148,7 +148,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void localeFromResolver() throws Exception { + void localeFromResolver() throws Exception { Locale locale = Locale.ENGLISH; servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale)); @@ -161,7 +161,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void timeZone() throws Exception { + void timeZone() throws Exception { MethodParameter timeZoneParameter = new MethodParameter(method, 8); assertThat(resolver.supportsParameter(timeZoneParameter)).as("TimeZone not supported").isTrue(); @@ -170,7 +170,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void timeZoneFromResolver() throws Exception { + void timeZoneFromResolver() throws Exception { TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles"); servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(Locale.US, timeZone)); @@ -183,7 +183,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void zoneId() throws Exception { + void zoneId() throws Exception { MethodParameter zoneIdParameter = new MethodParameter(method, 9); assertThat(resolver.supportsParameter(zoneIdParameter)).as("ZoneId not supported").isTrue(); @@ -192,7 +192,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void zoneIdFromResolver() throws Exception { + void zoneIdFromResolver() throws Exception { TimeZone timeZone = TimeZone.getTimeZone("America/New_York"); servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(Locale.US, timeZone)); @@ -205,7 +205,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void inputStream() throws Exception { + void inputStream() throws Exception { MethodParameter inputStreamParameter = new MethodParameter(method, 5); assertThat(resolver.supportsParameter(inputStreamParameter)).as("InputStream not supported").isTrue(); @@ -214,7 +214,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void reader() throws Exception { + void reader() throws Exception { MethodParameter readerParameter = new MethodParameter(method, 6); assertThat(resolver.supportsParameter(readerParameter)).as("Reader not supported").isTrue(); @@ -223,7 +223,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void webRequest() throws Exception { + void webRequest() throws Exception { MethodParameter webRequestParameter = new MethodParameter(method, 7); assertThat(resolver.supportsParameter(webRequestParameter)).as("WebRequest not supported").isTrue(); @@ -232,7 +232,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void httpMethod() throws Exception { + void httpMethod() throws Exception { MethodParameter httpMethodParameter = new MethodParameter(method, 10); assertThat(resolver.supportsParameter(httpMethodParameter)).as("HttpMethod not supported").isTrue(); @@ -241,7 +241,7 @@ public class ServletRequestMethodArgumentResolverTests { } @Test - public void pushBuilder() throws Exception { + void pushBuilder() throws Exception { final PushBuilder pushBuilder = mock(); servletRequest = new MockHttpServletRequest("GET", "") { @Override diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolverTests.java index b0ed4c8b987..496b0169aa3 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Arjen Poutsma */ -public class ServletResponseMethodArgumentResolverTests { +class ServletResponseMethodArgumentResolverTests { private ServletResponseMethodArgumentResolver resolver; @@ -51,7 +51,7 @@ public class ServletResponseMethodArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { resolver = new ServletResponseMethodArgumentResolver(); mavContainer = new ModelAndViewContainer(); servletResponse = new MockHttpServletResponse(); @@ -62,7 +62,7 @@ public class ServletResponseMethodArgumentResolverTests { @Test - public void servletResponse() throws Exception { + void servletResponse() throws Exception { MethodParameter servletResponseParameter = new MethodParameter(method, 0); assertThat(resolver.supportsParameter(servletResponseParameter)).as("ServletResponse not supported").isTrue(); @@ -81,7 +81,7 @@ public class ServletResponseMethodArgumentResolverTests { } @Test - public void outputStream() throws Exception { + void outputStream() throws Exception { MethodParameter outputStreamParameter = new MethodParameter(method, 1); assertThat(resolver.supportsParameter(outputStreamParameter)).as("OutputStream not supported").isTrue(); @@ -91,7 +91,7 @@ public class ServletResponseMethodArgumentResolverTests { } @Test - public void writer() throws Exception { + void writer() throws Exception { MethodParameter writerParameter = new MethodParameter(method, 2); assertThat(resolver.supportsParameter(writerParameter)).as("Writer not supported").isTrue(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/SessionAttributeMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/SessionAttributeMethodArgumentResolverTests.java index a0c325d1ac2..2000f1afc42 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/SessionAttributeMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/SessionAttributeMethodArgumentResolverTests.java @@ -25,7 +25,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; * @author Rossen Stoyanchev * @since 4.3 */ -public class SessionAttributeMethodArgumentResolverTests extends AbstractRequestAttributesArgumentResolverTests { +class SessionAttributeMethodArgumentResolverTests extends AbstractRequestAttributesArgumentResolverTests { @Override protected HandlerMethodArgumentResolver createResolver() { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitterTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitterTests.java index 67273705513..ba886f626e0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitterTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitterTests.java @@ -38,7 +38,7 @@ import static org.springframework.web.servlet.mvc.method.annotation.SseEmitter.e * * @author Rossen Stoyanchev */ -public class SseEmitterTests { +class SseEmitterTests { private static final MediaType TEXT_PLAIN_UTF8 = new MediaType("text", "plain", StandardCharsets.UTF_8); @@ -49,7 +49,7 @@ public class SseEmitterTests { @BeforeEach - public void setup() throws IOException { + void setup() throws IOException { this.handler = new TestHandler(); this.emitter = new SseEmitter(); this.emitter.initialize(this.handler); @@ -57,7 +57,7 @@ public class SseEmitterTests { @Test - public void send() throws Exception { + void send() throws Exception { this.emitter.send("foo"); this.handler.assertSentObjectCount(3); this.handler.assertObject(0, "data:", TEXT_PLAIN_UTF8); @@ -67,7 +67,7 @@ public class SseEmitterTests { } @Test - public void sendWithMediaType() throws Exception { + void sendWithMediaType() throws Exception { this.emitter.send("foo", MediaType.TEXT_PLAIN); this.handler.assertSentObjectCount(3); this.handler.assertObject(0, "data:", TEXT_PLAIN_UTF8); @@ -77,14 +77,14 @@ public class SseEmitterTests { } @Test - public void sendEventEmpty() throws Exception { + void sendEventEmpty() throws Exception { this.emitter.send(event()); this.handler.assertSentObjectCount(0); this.handler.assertWriteCount(0); } @Test - public void sendEventWithDataLine() throws Exception { + void sendEventWithDataLine() throws Exception { this.emitter.send(event().data("foo")); this.handler.assertSentObjectCount(3); this.handler.assertObject(0, "data:", TEXT_PLAIN_UTF8); @@ -94,7 +94,7 @@ public class SseEmitterTests { } @Test - public void sendEventWithTwoDataLines() throws Exception { + void sendEventWithTwoDataLines() throws Exception { this.emitter.send(event().data("foo").data("bar")); this.handler.assertSentObjectCount(5); this.handler.assertObject(0, "data:", TEXT_PLAIN_UTF8); @@ -106,7 +106,7 @@ public class SseEmitterTests { } @Test - public void sendEventWithMultiline() throws Exception { + void sendEventWithMultiline() throws Exception { this.emitter.send(event().data("foo\nbar\nbaz")); this.handler.assertSentObjectCount(3); this.handler.assertObject(0, "data:", TEXT_PLAIN_UTF8); @@ -116,7 +116,7 @@ public class SseEmitterTests { } @Test - public void sendEventFull() throws Exception { + void sendEventFull() throws Exception { this.emitter.send(event().comment("blah").name("test").reconnectTime(5000L).id("1").data("foo")); this.handler.assertSentObjectCount(3); this.handler.assertObject(0, ":blah\nevent:test\nretry:5000\nid:1\ndata:", TEXT_PLAIN_UTF8); @@ -126,7 +126,7 @@ public class SseEmitterTests { } @Test - public void sendEventFullWithTwoDataLinesInTheMiddle() throws Exception { + void sendEventFullWithTwoDataLinesInTheMiddle() throws Exception { this.emitter.send(event().comment("blah").data("foo").data("bar").name("test").reconnectTime(5000L).id("1")); this.handler.assertSentObjectCount(5); this.handler.assertObject(0, ":blah\ndata:", TEXT_PLAIN_UTF8); @@ -166,14 +166,14 @@ public class SseEmitterTests { } @Override - public void send(Object data, @Nullable MediaType mediaType) throws IOException { + public void send(Object data, @Nullable MediaType mediaType) { this.objects.add(data); this.mediaTypes.add(mediaType); this.writeCount++; } @Override - public void send(Set items) throws IOException { + public void send(Set items) { for (ResponseBodyEmitter.DataWithMediaType item : items) { this.objects.add(item.getData()); this.mediaTypes.add(item.getMediaType()); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandlerTests.java index 3531b3c7427..87bfd0966e9 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandlerTests.java @@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class StreamingResponseBodyReturnValueHandlerTests { +class StreamingResponseBodyReturnValueHandlerTests { private StreamingResponseBodyReturnValueHandler handler; @@ -59,7 +59,7 @@ public class StreamingResponseBodyReturnValueHandlerTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { this.handler = new StreamingResponseBodyReturnValueHandler(); this.mavContainer = new ModelAndViewContainer(); @@ -74,7 +74,7 @@ public class StreamingResponseBodyReturnValueHandlerTests { @Test - public void supportsReturnType() throws Exception { + void supportsReturnType() throws Exception { assertThat(this.handler.supportsReturnType(returnType(TestController.class, "handle"))).isTrue(); assertThat(this.handler.supportsReturnType(returnType(TestController.class, "handleResponseEntity"))).isTrue(); assertThat(this.handler.supportsReturnType(returnType(TestController.class, "handleResponseEntityString"))).isFalse(); @@ -82,7 +82,7 @@ public class StreamingResponseBodyReturnValueHandlerTests { } @Test - public void streamingResponseBody() throws Exception { + void streamingResponseBody() throws Exception { CountDownLatch latch = new CountDownLatch(1); MethodParameter returnType = returnType(TestController.class, "handle"); @@ -99,7 +99,7 @@ public class StreamingResponseBodyReturnValueHandlerTests { @Test - public void responseEntity() throws Exception { + void responseEntity() throws Exception { CountDownLatch latch = new CountDownLatch(1); MethodParameter returnType = returnType(TestController.class, "handleResponseEntity"); @@ -120,7 +120,7 @@ public class StreamingResponseBodyReturnValueHandlerTests { } @Test - public void responseEntityNoContent() throws Exception { + void responseEntityNoContent() throws Exception { MethodParameter returnType = returnType(TestController.class, "handleResponseEntity"); ResponseEntity emitter = ResponseEntity.noContent().build(); this.handler.handleReturnValue(emitter, returnType, this.mavContainer, this.webRequest); @@ -130,7 +130,7 @@ public class StreamingResponseBodyReturnValueHandlerTests { } @Test - public void responseEntityWithHeadersAndNoContent() throws Exception { + void responseEntityWithHeadersAndNoContent() throws Exception { ResponseEntity emitter = ResponseEntity.noContent().header("foo", "bar").build(); MethodParameter returnType = returnType(TestController.class, "handleResponseEntity"); this.handler.handleReturnValue(emitter, returnType, this.mavContainer, this.webRequest); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolverTests.java index 3c412d8ceb4..79bbffa587f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class UriComponentsBuilderMethodArgumentResolverTests { +class UriComponentsBuilderMethodArgumentResolverTests { private UriComponentsBuilderMethodArgumentResolver resolver; @@ -49,7 +49,7 @@ public class UriComponentsBuilderMethodArgumentResolverTests { @BeforeEach - public void setup() throws Exception { + void setup() throws Exception { this.resolver = new UriComponentsBuilderMethodArgumentResolver(); this.servletRequest = new MockHttpServletRequest(); this.webRequest = new ServletWebRequest(this.servletRequest); @@ -63,14 +63,14 @@ public class UriComponentsBuilderMethodArgumentResolverTests { @Test - public void supportsParameter() throws Exception { + void supportsParameter() throws Exception { assertThat(this.resolver.supportsParameter(this.builderParam)).isTrue(); assertThat(this.resolver.supportsParameter(this.servletBuilderParam)).isTrue(); assertThat(this.resolver.supportsParameter(this.intParam)).isFalse(); } @Test - public void resolveArgument() throws Exception { + void resolveArgument() throws Exception { this.servletRequest.setContextPath("/myapp"); this.servletRequest.setServletPath("/main"); this.servletRequest.setPathInfo("/accounts"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java index 89cbf094fd7..005c0edbc1e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -54,7 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rossen Stoyanchev * @since 3.1 */ -public class UriTemplateServletAnnotationControllerHandlerMethodTests extends AbstractServletHandlerMethodTests { +class UriTemplateServletAnnotationControllerHandlerMethodTests extends AbstractServletHandlerMethodTests { @SuppressWarnings("unused") static Stream pathPatternsArguments() { @@ -664,7 +664,7 @@ public class UriTemplateServletAnnotationControllerHandlerMethodTests extends Ab } @Override - public View resolveViewName(final String viewName, Locale locale) throws Exception { + public View resolveViewName(final String viewName, Locale locale) { return new AbstractView () { @Override public String getContentType() { @@ -672,7 +672,7 @@ public class UriTemplateServletAnnotationControllerHandlerMethodTests extends Ab } @Override protected void renderMergedOutputModel(Map model, HttpServletRequest request, - HttpServletResponse response) throws Exception { + HttpServletResponse response) { for (String key : attrsToValidate.keySet()) { assertThat(model.containsKey(key)).as("Model should contain attribute named " + key).isTrue(); assertThat(model.get(key)).isEqualTo(attrsToValidate.get(key)); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandlerTests.java index dd44641531b..0656bda4981 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class ViewMethodReturnValueHandlerTests { +class ViewMethodReturnValueHandlerTests { private ViewMethodReturnValueHandler handler; @@ -48,7 +48,7 @@ public class ViewMethodReturnValueHandlerTests { @BeforeEach - public void setup() { + void setup() { this.handler = new ViewMethodReturnValueHandler(); this.mavContainer = new ModelAndViewContainer(); this.webRequest = new ServletWebRequest(new MockHttpServletRequest()); @@ -56,12 +56,12 @@ public class ViewMethodReturnValueHandlerTests { @Test - public void supportsReturnType() throws Exception { + void supportsReturnType() throws Exception { assertThat(this.handler.supportsReturnType(createReturnValueParam("view"))).isTrue(); } @Test - public void returnView() throws Exception { + void returnView() throws Exception { InternalResourceView view = new InternalResourceView("testView"); this.handler.handleReturnValue(view, createReturnValueParam("view"), this.mavContainer, this.webRequest); @@ -69,7 +69,7 @@ public class ViewMethodReturnValueHandlerTests { } @Test - public void returnViewRedirect() throws Exception { + void returnViewRedirect() throws Exception { RedirectView redirectView = new RedirectView("testView"); ModelMap redirectModel = new RedirectAttributesModelMap(); this.mavContainer.setRedirectModel(redirectModel); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandlerTests.java index 6e0ce9b5e9a..233223a9f43 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ViewNameMethodReturnValueHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class ViewNameMethodReturnValueHandlerTests { +class ViewNameMethodReturnValueHandlerTests { private ViewNameMethodReturnValueHandler handler; @@ -45,7 +45,7 @@ public class ViewNameMethodReturnValueHandlerTests { @BeforeEach - public void setup() throws NoSuchMethodException { + void setup() throws NoSuchMethodException { this.handler = new ViewNameMethodReturnValueHandler(); this.mavContainer = new ModelAndViewContainer(); this.webRequest = new ServletWebRequest(new MockHttpServletRequest()); @@ -55,18 +55,18 @@ public class ViewNameMethodReturnValueHandlerTests { @Test - public void supportsReturnType() throws Exception { + void supportsReturnType() throws Exception { assertThat(this.handler.supportsReturnType(this.param)).isTrue(); } @Test - public void returnViewName() throws Exception { + void returnViewName() throws Exception { this.handler.handleReturnValue("testView", this.param, this.mavContainer, this.webRequest); assertThat(this.mavContainer.getViewName()).isEqualTo("testView"); } @Test - public void returnViewNameRedirect() throws Exception { + void returnViewNameRedirect() throws Exception { ModelMap redirectModel = new RedirectAttributesModelMap(); this.mavContainer.setRedirectModel(redirectModel); this.handler.handleReturnValue("redirect:testView", this.param, this.mavContainer, this.webRequest); @@ -75,7 +75,7 @@ public class ViewNameMethodReturnValueHandlerTests { } @Test - public void returnViewCustomRedirect() throws Exception { + void returnViewCustomRedirect() throws Exception { ModelMap redirectModel = new RedirectAttributesModelMap(); this.mavContainer.setRedirectModel(redirectModel); this.handler.setRedirectPatterns("myRedirect:*"); @@ -85,7 +85,7 @@ public class ViewNameMethodReturnValueHandlerTests { } @Test - public void returnViewRedirectWithCustomRedirectPattern() throws Exception { + void returnViewRedirectWithCustomRedirectPattern() throws Exception { ModelMap redirectModel = new RedirectAttributesModelMap(); this.mavContainer.setRedirectModel(redirectModel); this.handler.setRedirectPatterns("myRedirect:*"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java index 67f8cd8f506..8ea32e43d86 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java @@ -61,7 +61,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Arjen Poutsma * @author Sebastien Deleuze */ -public class DefaultHandlerExceptionResolverTests { +class DefaultHandlerExceptionResolverTests { private final DefaultHandlerExceptionResolver exceptionResolver = new DefaultHandlerExceptionResolver(); @@ -71,13 +71,13 @@ public class DefaultHandlerExceptionResolverTests { @BeforeEach - public void setup() { + void setup() { exceptionResolver.setWarnLogCategory(exceptionResolver.getClass().getName()); } @Test - public void handleHttpRequestMethodNotSupported() { + void handleHttpRequestMethodNotSupported() { HttpRequestMethodNotSupportedException ex = new HttpRequestMethodNotSupportedException("GET", Arrays.asList("POST", "PUT")); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); @@ -88,7 +88,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleHttpMediaTypeNotSupported() { + void handleHttpMediaTypeNotSupported() { HttpMediaTypeNotSupportedException ex = new HttpMediaTypeNotSupportedException(new MediaType("text", "plain"), Collections.singletonList(new MediaType("application", "pdf"))); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); @@ -99,7 +99,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void patchHttpMediaTypeNotSupported() { + void patchHttpMediaTypeNotSupported() { HttpMediaTypeNotSupportedException ex = new HttpMediaTypeNotSupportedException( new MediaType("text", "plain"), Collections.singletonList(new MediaType("application", "pdf")), @@ -113,7 +113,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleMissingPathVariable() throws NoSuchMethodException { + void handleMissingPathVariable() throws NoSuchMethodException { Method method = getClass().getMethod("handle", String.class); MethodParameter parameter = new MethodParameter(method, 0); MissingPathVariableException ex = new MissingPathVariableException("foo", parameter); @@ -125,7 +125,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleMissingServletRequestParameter() { + void handleMissingServletRequestParameter() { MissingServletRequestParameterException ex = new MissingServletRequestParameterException("foo", "bar"); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertThat(mav).as("No ModelAndView returned").isNotNull(); @@ -135,7 +135,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleServletRequestBindingException() { + void handleServletRequestBindingException() { String message = "Missing required value - header, cookie, or pathvar"; ServletRequestBindingException ex = new ServletRequestBindingException(message); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); @@ -145,7 +145,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleTypeMismatch() { + void handleTypeMismatch() { TypeMismatchException ex = new TypeMismatchException("foo", String.class); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertThat(mav).as("No ModelAndView returned").isNotNull(); @@ -164,7 +164,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleHttpMessageNotWritable() { + void handleHttpMessageNotWritable() { HttpMessageNotWritableException ex = new HttpMessageNotWritableException("foo"); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertThat(mav).as("No ModelAndView returned").isNotNull(); @@ -173,7 +173,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleMethodArgumentNotValid() throws Exception { + void handleMethodArgumentNotValid() throws Exception { BeanPropertyBindingResult errors = new BeanPropertyBindingResult(new TestBean(), "testBean"); errors.rejectValue("name", "invalid"); MethodParameter parameter = new MethodParameter(this.getClass().getMethod("handle", String.class), 0); @@ -185,7 +185,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleMissingServletRequestPartException() { + void handleMissingServletRequestPartException() { MissingServletRequestPartException ex = new MissingServletRequestPartException("name"); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertThat(mav).as("No ModelAndView returned").isNotNull(); @@ -197,7 +197,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleBindException() { + void handleBindException() { BindException ex = new BindException(new Object(), "name"); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertThat(mav).as("No ModelAndView returned").isNotNull(); @@ -206,7 +206,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleNoHandlerFoundException() { + void handleNoHandlerFoundException() { ServletServerHttpRequest req = new ServletServerHttpRequest( new MockHttpServletRequest("GET","/resource")); NoHandlerFoundException ex = new NoHandlerFoundException(req.getMethod().name(), @@ -218,7 +218,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleNoResourceFoundException() { + void handleNoResourceFoundException() { NoResourceFoundException ex = new NoResourceFoundException(HttpMethod.GET, "/resource"); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertThat(mav).as("No ModelAndView returned").isNotNull(); @@ -227,7 +227,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleConversionNotSupportedException() { + void handleConversionNotSupportedException() { ConversionNotSupportedException ex = new ConversionNotSupportedException(new Object(), String.class, new Exception()); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); @@ -249,7 +249,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void handleMaxUploadSizeExceededException() { + void handleMaxUploadSizeExceededException() { MaxUploadSizeExceededException ex = new MaxUploadSizeExceededException(1000); ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); assertThat(mav).as("No ModelAndView returned").isNotNull(); @@ -259,7 +259,7 @@ public class DefaultHandlerExceptionResolverTests { } @Test - public void customModelAndView() { + void customModelAndView() { ModelAndView expected = new ModelAndView(); HandlerExceptionResolver resolver = new DefaultHandlerExceptionResolver() { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/ParameterizableViewControllerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/ParameterizableViewControllerTests.java index 2b364bbcf0b..c864b33339c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/ParameterizableViewControllerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/ParameterizableViewControllerTests.java @@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rossen Stoyanchev * @since 4.1 */ -public class ParameterizableViewControllerTests { +class ParameterizableViewControllerTests { private final ParameterizableViewController controller = new ParameterizableViewController(); @@ -44,20 +44,20 @@ public class ParameterizableViewControllerTests { @Test - public void defaultViewName() throws Exception { + void defaultViewName() throws Exception { ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response); assertThat(modelAndView.getViewName()).isNull(); } @Test - public void viewName() throws Exception { + void viewName() throws Exception { this.controller.setViewName("view"); ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response); assertThat(modelAndView.getViewName()).isEqualTo("view"); } @Test - public void viewNameAndStatus() throws Exception { + void viewNameAndStatus() throws Exception { this.controller.setViewName("view"); this.controller.setStatusCode(HttpStatus.NOT_FOUND); ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response); @@ -66,7 +66,7 @@ public class ParameterizableViewControllerTests { } @Test - public void viewNameAndStatus204() throws Exception { + void viewNameAndStatus204() throws Exception { this.controller.setStatusCode(HttpStatus.NO_CONTENT); ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response); assertThat(modelAndView).isNull(); @@ -74,7 +74,7 @@ public class ParameterizableViewControllerTests { } @Test - public void redirectStatus() throws Exception { + void redirectStatus() throws Exception { this.controller.setStatusCode(HttpStatus.PERMANENT_REDIRECT); this.controller.setViewName("/foo"); ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response); @@ -85,7 +85,7 @@ public class ParameterizableViewControllerTests { } @Test - public void redirectStatusWithRedirectPrefix() throws Exception { + void redirectStatusWithRedirectPrefix() throws Exception { this.controller.setStatusCode(HttpStatus.PERMANENT_REDIRECT); this.controller.setViewName("redirect:/foo"); ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response); @@ -96,7 +96,7 @@ public class ParameterizableViewControllerTests { } @Test - public void redirectView() throws Exception { + void redirectView() throws Exception { RedirectView view = new RedirectView("/foo"); this.controller.setView(view); ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response); @@ -104,7 +104,7 @@ public class ParameterizableViewControllerTests { } @Test - public void statusOnly() throws Exception { + void statusOnly() throws Exception { this.controller.setStatusCode(HttpStatus.NOT_FOUND); this.controller.setStatusOnly(true); ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMapTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMapTests.java index 41ee86b0940..cb86d83ef37 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMapTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMapTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -45,7 +45,7 @@ class RedirectAttributesModelMapTests { private FormattingConversionService conversionService; @BeforeEach - public void setup() { + void setup() { this.conversionService = new DefaultFormattingConversionService(); DataBinder dataBinder = new DataBinder(null); dataBinder.setConversionService(conversionService); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/CachingResourceResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/CachingResourceResolverTests.java index 605880fdf82..96361e1d9e5 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/CachingResourceResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/CachingResourceResolverTests.java @@ -16,7 +16,6 @@ package org.springframework.web.servlet.resource; -import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -50,7 +49,7 @@ public class CachingResourceResolverTests { @BeforeEach - public void setup() { + void setup() { this.cache = new ConcurrentMapCache("resourceCache"); @@ -65,7 +64,7 @@ public class CachingResourceResolverTests { @Test - public void resolveResourceInternal() { + void resolveResourceInternal() { Resource expected = new ClassPathResource("test/bar.css", getClass()); Resource actual = this.chain.resolveResource(null, "bar.css", this.locations); @@ -74,7 +73,7 @@ public class CachingResourceResolverTests { } @Test - public void resolveResourceInternalFromCache() { + void resolveResourceInternalFromCache() { Resource expected = mock(); this.cache.put(resourceKey("bar.css"), expected); Resource actual = this.chain.resolveResource(null, "bar.css", this.locations); @@ -83,12 +82,12 @@ public class CachingResourceResolverTests { } @Test - public void resolveResourceInternalNoMatch() { + void resolveResourceInternalNoMatch() { assertThat(this.chain.resolveResource(null, "invalid.css", this.locations)).isNull(); } @Test - public void resolverUrlPath() { + void resolverUrlPath() { String expected = "/foo.css"; String actual = this.chain.resolveUrlPath(expected, this.locations); @@ -96,7 +95,7 @@ public class CachingResourceResolverTests { } @Test - public void resolverUrlPathFromCache() { + void resolverUrlPathFromCache() { String expected = "cached-imaginary.css"; this.cache.put(CachingResourceResolver.RESOLVED_URL_PATH_CACHE_KEY_PREFIX + "imaginary.css", expected); String actual = this.chain.resolveUrlPath("imaginary.css", this.locations); @@ -105,12 +104,12 @@ public class CachingResourceResolverTests { } @Test - public void resolverUrlPathNoMatch() { + void resolverUrlPathNoMatch() { assertThat(this.chain.resolveUrlPath("invalid.css", this.locations)).isNull(); } @Test - public void resolveResourceAcceptEncodingInCacheKey(GzippedFiles gzippedFiles) throws IOException { + void resolveResourceAcceptEncodingInCacheKey(GzippedFiles gzippedFiles) { String file = "bar.css"; gzippedFiles.create(file); @@ -143,7 +142,7 @@ public class CachingResourceResolverTests { } @Test - public void resolveResourceNoAcceptEncoding() { + void resolveResourceNoAcceptEncoding() { String file = "bar.css"; MockHttpServletRequest request = new MockHttpServletRequest("GET", file); Resource expected = this.chain.resolveResource(request, file, this.locations); @@ -155,7 +154,7 @@ public class CachingResourceResolverTests { } @Test - public void resolveResourceMatchingEncoding() { + void resolveResourceMatchingEncoding() { Resource resource = mock(); Resource gzipped = mock(); this.cache.put(resourceKey("bar.css"), resource); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ContentBasedVersionStrategyTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ContentBasedVersionStrategyTests.java index bb3b9a3e23c..7c0cd8003f6 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ContentBasedVersionStrategyTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ContentBasedVersionStrategyTests.java @@ -35,19 +35,19 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Brian Clozel * @author Rossen Stoyanchev */ -public class ContentBasedVersionStrategyTests { +class ContentBasedVersionStrategyTests { - private ContentVersionStrategy versionStrategy = new ContentVersionStrategy(); + private final ContentVersionStrategy versionStrategy = new ContentVersionStrategy(); @BeforeEach - public void setup() { + void setup() { VersionResourceResolver versionResourceResolver = new VersionResourceResolver(); versionResourceResolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy)); } @Test - public void extractVersion() { + void extractVersion() { String hash = "7fbe76cdac6093784895bb4989203e5a"; String path = "font-awesome/css/font-awesome.min-" + hash + ".css"; @@ -56,7 +56,7 @@ public class ContentBasedVersionStrategyTests { } @Test - public void removeVersion() { + void removeVersion() { String hash = "7fbe76cdac6093784895bb4989203e5a"; String file = "font-awesome/css/font-awesome.min%s%s.css"; @@ -64,7 +64,7 @@ public class ContentBasedVersionStrategyTests { } @Test - public void getResourceVersion() throws IOException { + void getResourceVersion() throws IOException { Resource expected = new ClassPathResource("test/bar.css", getClass()); String hash = DigestUtils.md5DigestAsHex(FileCopyUtils.copyToByteArray(expected.getInputStream())); @@ -72,7 +72,7 @@ public class ContentBasedVersionStrategyTests { } @Test - public void addVersionToUrl() { + void addVersionToUrl() { assertThat(this.versionStrategy.addVersion("test/bar.css", "123")).isEqualTo("test/bar-123.css"); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/EncodedResourceResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/EncodedResourceResolverTests.java index 86b94944612..f7f94962f66 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/EncodedResourceResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/EncodedResourceResolverTests.java @@ -47,17 +47,15 @@ public class EncodedResourceResolverTests { private List locations; - private Cache cache; - @BeforeEach - public void setup() { - this.cache = new ConcurrentMapCache("resourceCache"); + void setup() { + Cache cache = new ConcurrentMapCache("resourceCache"); VersionResourceResolver versionResolver = new VersionResourceResolver(); versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy())); List resolvers = new ArrayList<>(); - resolvers.add(new CachingResourceResolver(this.cache)); + resolvers.add(new CachingResourceResolver(cache)); resolvers.add(new EncodedResourceResolver()); resolvers.add(versionResolver); resolvers.add(new PathResourceResolver()); @@ -70,7 +68,7 @@ public class EncodedResourceResolverTests { @Test - public void resolveGzipped(GzippedFiles gzippedFiles) { + void resolveGzipped(GzippedFiles gzippedFiles) { String file = "js/foo.js"; gzippedFiles.create(file); MockHttpServletRequest request = new MockHttpServletRequest(); @@ -88,7 +86,7 @@ public class EncodedResourceResolverTests { } @Test - public void resolveGzippedWithVersion(GzippedFiles gzippedFiles) { + void resolveGzippedWithVersion(GzippedFiles gzippedFiles) { gzippedFiles.create("foo.css"); String file = "foo-e36d2e05253c6c7085a91522ce43a0b4.css"; MockHttpServletRequest request = new MockHttpServletRequest(); @@ -102,7 +100,7 @@ public class EncodedResourceResolverTests { } @Test - public void resolveFromCacheWithEncodingVariants(GzippedFiles gzippedFiles) { + void resolveFromCacheWithEncodingVariants(GzippedFiles gzippedFiles) { // 1. Resolve, and cache .gz variant String file = "js/foo.js"; gzippedFiles.create(file); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/FixedVersionStrategyTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/FixedVersionStrategyTests.java index 36a31290ed6..d7dab1e62d9 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/FixedVersionStrategyTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/FixedVersionStrategyTests.java @@ -28,7 +28,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Brian Clozel * @author Rossen Stoyanchev */ -public class FixedVersionStrategyTests { +class FixedVersionStrategyTests { private static final String VERSION = "1df341f"; @@ -39,30 +39,30 @@ public class FixedVersionStrategyTests { @BeforeEach - public void setup() { + void setup() { this.strategy = new FixedVersionStrategy(VERSION); } @Test - public void emptyPrefixVersion() { + void emptyPrefixVersion() { assertThatIllegalArgumentException().isThrownBy(() -> new FixedVersionStrategy(" ")); } @Test - public void extractVersion() { + void extractVersion() { assertThat(this.strategy.extractVersion(VERSION + "/" + PATH)).isEqualTo(VERSION); assertThat(this.strategy.extractVersion(PATH)).isNull(); } @Test - public void removeVersion() { + void removeVersion() { assertThat(this.strategy.removeVersion(VERSION + "/" + PATH, VERSION)).isEqualTo(("/" + PATH)); } @Test - public void addVersion() { + void addVersion() { assertThat(this.strategy.addVersion("/" + PATH, VERSION)).isEqualTo((VERSION + "/" + PATH)); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java index 8c1e7ea46ce..b57427b6ad4 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -47,7 +47,7 @@ class GzipSupport implements AfterEachCallback, ParameterResolver { private static final Namespace namespace = Namespace.create(GzipSupport.class); @Override - public void afterEach(ExtensionContext context) throws Exception { + public void afterEach(ExtensionContext context) { GzippedFiles gzippedFiles = getStore(context).remove(GzippedFiles.class, GzippedFiles.class); if (gzippedFiles != null) { for (File gzippedFile: gzippedFiles.created) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java index 1eb07b9b787..5cc34dd9a40 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java @@ -40,13 +40,13 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Brian Clozel * @author Rossen Stoyanchev */ -public class PathResourceResolverTests { +class PathResourceResolverTests { private final PathResourceResolver resolver = new PathResourceResolver(); @Test - public void resolveFromClasspath() throws IOException { + void resolveFromClasspath() throws IOException { Resource location = new ClassPathResource("test/", PathResourceResolver.class); String requestPath = "bar.css"; Resource actual = this.resolver.resolveResource(null, requestPath, Collections.singletonList(location), null); @@ -55,7 +55,7 @@ public class PathResourceResolverTests { } @Test - public void resolveFromClasspathRoot() { + void resolveFromClasspathRoot() { Resource location = new ClassPathResource("/"); String requestPath = "org/springframework/web/servlet/resource/test/bar.css"; Resource actual = this.resolver.resolveResource(null, requestPath, Collections.singletonList(location), null); @@ -64,7 +64,7 @@ public class PathResourceResolverTests { } @Test - public void checkResource() throws IOException { + void checkResource() { Resource location = new ClassPathResource("test/", PathResourceResolver.class); testCheckResource(location, "../testsecret/secret.txt"); testCheckResource(location, "test/../../testsecret/secret.txt"); @@ -82,7 +82,7 @@ public class PathResourceResolverTests { testCheckResource(location, "url:" + secretPath); } - private void testCheckResource(Resource location, String requestPath) throws IOException { + private void testCheckResource(Resource location, String requestPath) { List locations = Collections.singletonList(location); Resource actual = this.resolver.resolveResource(null, requestPath, locations, null); assertThat(actual).isNull(); @@ -100,7 +100,7 @@ public class PathResourceResolverTests { } @Test - public void checkResourceWithAllowedLocations() { + void checkResourceWithAllowedLocations() { this.resolver.setAllowedLocations( new ClassPathResource("test/", PathResourceResolver.class), new ClassPathResource("testalternatepath/", PathResourceResolver.class) @@ -150,7 +150,7 @@ public class PathResourceResolverTests { } @Test - public void relativePathEncodedForUrlResource() throws Exception { + void relativePathEncodedForUrlResource() throws Exception { TestUrlResource location = new TestUrlResource("file:///tmp"); List locations = Collections.singletonList(location); @@ -194,7 +194,7 @@ public class PathResourceResolverTests { } @Override - public Resource createRelative(String relativePath) throws MalformedURLException { + public Resource createRelative(String relativePath) { this.relativePath = relativePath; return this; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerIntegrationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerIntegrationTests.java index 9dc6c4ffb5c..6046b5e1c43 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerIntegrationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -57,7 +57,7 @@ import static org.junit.jupiter.params.provider.Arguments.arguments; * * @author Rossen Stoyanchev */ -public class ResourceHttpRequestHandlerIntegrationTests { +class ResourceHttpRequestHandlerIntegrationTests { private final MockServletContext servletContext = new MockServletContext(); 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 8895d51bae8..28db86a9798 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 @@ -572,7 +572,7 @@ class ResourceHttpRequestHandlerTests { @BeforeEach - void setup() throws Exception { + void setup() { TestServletContext servletContext = new TestServletContext(); this.handler = new ResourceHttpRequestHandler(); this.handler.setLocations(List.of(testResource, testAlternatePathResource, webjarsResource)); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceTransformerSupportTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceTransformerSupportTests.java index 74a0ec5a8e4..afbbe14faff 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceTransformerSupportTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceTransformerSupportTests.java @@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Brian Clozel * @author Rossen Stoyanchev */ -public class ResourceTransformerSupportTests { +class ResourceTransformerSupportTests { private ResourceTransformerChain transformerChain; @@ -46,7 +46,7 @@ public class ResourceTransformerSupportTests { @BeforeEach - public void setUp() { + void setUp() { VersionResourceResolver versionResolver = new VersionResourceResolver(); versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy())); PathResourceResolver pathResolver = new PathResourceResolver(); @@ -72,7 +72,7 @@ public class ResourceTransformerSupportTests { @Test - public void resolveUrlPath() { + void resolveUrlPath() { this.request.setRequestURI("/context/servlet/resources/main.css"); this.request.setContextPath("/context"); this.request.setServletPath("/servlet"); @@ -84,7 +84,7 @@ public class ResourceTransformerSupportTests { } @Test - public void resolveUrlPathWithRelativePath() { + void resolveUrlPathWithRelativePath() { Resource resource = getResource("main.css"); String actual = this.transformer.resolveUrlPath("bar.css", this.request, resource, this.transformerChain); @@ -92,7 +92,7 @@ public class ResourceTransformerSupportTests { } @Test - public void resolveUrlPathWithRelativePathInParentDirectory() { + void resolveUrlPathWithRelativePathInParentDirectory() { Resource resource = getResource("images/image.png"); String actual = this.transformer.resolveUrlPath("../bar.css", this.request, resource, this.transformerChain); @@ -100,7 +100,7 @@ public class ResourceTransformerSupportTests { } @Test - public void toAbsolutePath() { + void toAbsolutePath() { String absolute = this.transformer.toAbsolutePath("img/image.png", new MockHttpServletRequest("GET", "/resources/style.css")); assertThat(absolute).isEqualTo("/resources/img/image.png"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilterTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilterTests.java index f19a06a21bb..0e67f6be704 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilterTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilterTests.java @@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; * * @author Brian Clozel */ -public class ResourceUrlEncodingFilterTests { +class ResourceUrlEncodingFilterTests { private ResourceUrlEncodingFilter filter; @@ -49,7 +49,7 @@ public class ResourceUrlEncodingFilterTests { @BeforeEach - public void createFilter() { + void createFilter() { VersionResourceResolver versionResolver = new VersionResourceResolver(); versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy())); PathResourceResolver pathResolver = new PathResourceResolver(); @@ -74,13 +74,13 @@ public class ResourceUrlEncodingFilterTests { @Test - public void encodeURL() throws Exception { + void encodeURL() throws Exception { testEncodeUrl(new MockHttpServletRequest("GET", "/"), "/resources/bar.css", "/resources/bar-11e16cf79faee7ac698c805cf28248d2.css"); } @Test - public void encodeUrlWithContext() throws Exception { + void encodeUrlWithContext() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/context/foo"); request.setContextPath("/context"); @@ -90,7 +90,7 @@ public class ResourceUrlEncodingFilterTests { @Test - public void encodeUrlWithContextAndForwardedRequest() throws Exception { + void encodeUrlWithContextAndForwardedRequest() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/context/foo"); request.setContextPath("/context"); @@ -113,7 +113,7 @@ public class ResourceUrlEncodingFilterTests { } @Test - public void encodeContextPathUrlWithSuffix() throws Exception { + void encodeContextPathUrlWithSuffix() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/context/"); request.setContextPath("/context"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderJavaConfigTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderJavaConfigTests.java index 82e8e6f18fe..c2170c48209 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderJavaConfigTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderJavaConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class ResourceUrlProviderJavaConfigTests { +class ResourceUrlProviderJavaConfigTests { private final TestServlet servlet = new TestServlet(); @@ -52,7 +52,6 @@ public class ResourceUrlProviderJavaConfigTests { @BeforeEach - @SuppressWarnings("resource") public void setup() throws Exception { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); @@ -73,7 +72,7 @@ public class ResourceUrlProviderJavaConfigTests { } @Test - public void resolvePathWithServletMappedAsRoot() throws Exception { + void resolvePathWithServletMappedAsRoot() throws Exception { this.request.setRequestURI("/myapp/index"); this.request.setServletPath("/index"); this.filterChain.doFilter(this.request, this.response); @@ -82,7 +81,7 @@ public class ResourceUrlProviderJavaConfigTests { } @Test - public void resolvePathWithServletMappedByPrefix() throws Exception { + void resolvePathWithServletMappedByPrefix() throws Exception { this.request.setRequestURI("/myapp/myservlet/index"); this.request.setServletPath("/myservlet"); this.filterChain.doFilter(this.request, this.response); @@ -91,7 +90,7 @@ public class ResourceUrlProviderJavaConfigTests { } @Test - public void resolvePathNoMatch() throws Exception { + void resolvePathNoMatch() throws Exception { this.request.setRequestURI("/myapp/myservlet/index"); this.request.setServletPath("/myservlet"); this.filterChain.doFilter(this.request, this.response); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderTests.java index 8ddcb6e399f..2609bebcc44 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlProviderTests.java @@ -46,7 +46,7 @@ import static org.mockito.Mockito.mock; * @author Rossen Stoyanchev * @author Brian Clozel */ -public class ResourceUrlProviderTests { +class ResourceUrlProviderTests { private final List locations = new ArrayList<>(); @@ -117,7 +117,7 @@ public class ResourceUrlProviderTests { } @Test // SPR-12647 - void bestPatternMatch() throws Exception { + void bestPatternMatch() { ResourceHttpRequestHandler otherHandler = new ResourceHttpRequestHandler(); otherHandler.setLocations(this.locations); Map versionStrategyMap = new HashMap<>(); @@ -138,8 +138,7 @@ public class ResourceUrlProviderTests { } @Test // SPR-12592 - @SuppressWarnings("resource") - void initializeOnce() throws Exception { + void initializeOnce() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setServletContext(new MockServletContext()); context.register(HandlerMappingConfiguration.class); @@ -151,7 +150,6 @@ public class ResourceUrlProviderTests { } @Test - @SuppressWarnings("resource") void initializeOnCurrentContext() { AnnotationConfigWebApplicationContext parentContext = new AnnotationConfigWebApplicationContext(); parentContext.setServletContext(new MockServletContext()); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/VersionResourceResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/VersionResourceResolverTests.java index 3c3a01743f6..4aa73190ae0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/VersionResourceResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/VersionResourceResolverTests.java @@ -54,7 +54,7 @@ class VersionResourceResolverTests { @Test - void resolveResourceExisting() throws Exception { + void resolveResourceExisting() { String file = "bar.css"; Resource expected = new ClassPathResource("test/" + file, getClass()); given(this.chain.resolveResource(null, file, this.locations)).willReturn(expected); @@ -67,7 +67,7 @@ class VersionResourceResolverTests { } @Test - void resolveResourceNoVersionStrategy() throws Exception { + void resolveResourceNoVersionStrategy() { String file = "missing.css"; given(this.chain.resolveResource(null, file, this.locations)).willReturn(null); @@ -78,7 +78,7 @@ class VersionResourceResolverTests { } @Test - void resolveResourceNoVersionInPath() throws Exception { + void resolveResourceNoVersionInPath() { String file = "bar.css"; given(this.chain.resolveResource(null, file, this.locations)).willReturn(null); given(this.versionStrategy.extractVersion(file)).willReturn(""); @@ -91,7 +91,7 @@ class VersionResourceResolverTests { } @Test - void resolveResourceNoResourceAfterVersionRemoved() throws Exception { + void resolveResourceNoResourceAfterVersionRemoved() { String versionFile = "bar-version.css"; String version = "version"; String file = "bar.css"; @@ -107,7 +107,7 @@ class VersionResourceResolverTests { } @Test - void resolveResourceVersionDoesNotMatch() throws Exception { + void resolveResourceVersionDoesNotMatch() { String versionFile = "bar-version.css"; String version = "version"; String file = "bar.css"; @@ -125,7 +125,7 @@ class VersionResourceResolverTests { } @Test - void resolveResourceSuccess() throws Exception { + void resolveResourceSuccess() { String versionFile = "bar-version.css"; String version = "version"; String file = "bar.css"; @@ -147,7 +147,7 @@ class VersionResourceResolverTests { } @Test - void getStrategyForPath() throws Exception { + void getStrategyForPath() { Map strategies = new HashMap<>(); VersionStrategy jsStrategy = mock(); VersionStrategy catchAllStrategy = mock(); @@ -163,7 +163,7 @@ class VersionResourceResolverTests { // SPR-13883 @Test - void shouldConfigureFixedPrefixAutomatically() throws Exception { + void shouldConfigureFixedPrefixAutomatically() { this.resolver.addFixedVersionStrategy("fixedversion", "/js/**", "/css/**", "/fixedversion/css/**"); assertThat(this.resolver.getStrategyMap()).hasSize(4); @@ -174,7 +174,7 @@ class VersionResourceResolverTests { } @Test // SPR-15372 - void resolveUrlPathNoVersionStrategy() throws Exception { + void resolveUrlPathNoVersionStrategy() { given(this.chain.resolveUrlPath("/foo.css", this.locations)).willReturn("/foo.css"); String resolved = this.resolver.resolveUrlPathInternal("/foo.css", this.locations, this.chain); assertThat(resolved).isEqualTo("/foo.css"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/AnnotationConfigDispatcherServletInitializerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/AnnotationConfigDispatcherServletInitializerTests.java index 11197dee86b..ea09fd75b61 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/AnnotationConfigDispatcherServletInitializerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/AnnotationConfigDispatcherServletInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Arjen Poutsma */ -public class AnnotationConfigDispatcherServletInitializerTests { +class AnnotationConfigDispatcherServletInitializerTests { private static final String SERVLET_NAME = "myservlet"; @@ -72,7 +72,7 @@ public class AnnotationConfigDispatcherServletInitializerTests { @BeforeEach - public void setUp() throws Exception { + void setUp() { servletContext = new MyMockServletContext(); initializer = new MyAnnotationConfigDispatcherServletInitializer(); servlets = new LinkedHashMap<>(1); @@ -82,7 +82,7 @@ public class AnnotationConfigDispatcherServletInitializerTests { } @Test - public void register() throws ServletException { + void register() throws ServletException { initializer.onStartup(servletContext); assertThat(servlets).hasSize(1); @@ -122,7 +122,7 @@ public class AnnotationConfigDispatcherServletInitializerTests { } @Test - public void asyncSupportedFalse() throws ServletException { + void asyncSupportedFalse() throws ServletException { initializer = new MyAnnotationConfigDispatcherServletInitializer() { @Override protected boolean isAsyncSupported() { @@ -143,7 +143,7 @@ public class AnnotationConfigDispatcherServletInitializerTests { // SPR-11357 @Test - public void rootContextOnly() throws ServletException { + void rootContextOnly() throws ServletException { initializer = new MyAnnotationConfigDispatcherServletInitializer() { @Override protected Class[] getRootConfigClasses() { @@ -169,7 +169,7 @@ public class AnnotationConfigDispatcherServletInitializerTests { } @Test - public void noFilters() throws ServletException { + void noFilters() throws ServletException { initializer = new MyAnnotationConfigDispatcherServletInitializer() { @Override protected Filter[] getServletFilters() { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/DispatcherServletInitializerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/DispatcherServletInitializerTests.java index a527d1db4b4..1b6bd2d0366 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/DispatcherServletInitializerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/DispatcherServletInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Arjen Poutsma */ -public class DispatcherServletInitializerTests { +class DispatcherServletInitializerTests { private static final String SERVLET_NAME = "myservlet"; @@ -56,7 +56,7 @@ public class DispatcherServletInitializerTests { @Test - public void register() throws ServletException { + void register() throws ServletException { initializer.onStartup(servletContext); assertThat(servlets).hasSize(1); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/FlashMapManagerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/FlashMapManagerTests.java index 08e70e43a4b..5637f9fb120 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/FlashMapManagerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/FlashMapManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -29,6 +29,7 @@ import jakarta.servlet.http.HttpServletResponse; import org.assertj.core.api.ObjectAssert; import org.junit.jupiter.api.Test; +import org.springframework.lang.Nullable; import org.springframework.web.servlet.FlashMap; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import org.springframework.web.testfixture.servlet.MockHttpServletResponse; @@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rossen Stoyanchev * @author Sam Brannen */ -public class FlashMapManagerTests { +class FlashMapManagerTests { private final TestFlashMapManager flashMapManager = new TestFlashMapManager(); @@ -52,12 +53,12 @@ public class FlashMapManagerTests { @Test - public void retrieveAndUpdateMatchByPath() { + void retrieveAndUpdateMatchByPath() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/path"); - this.flashMapManager.setFlashMaps(Arrays.asList(flashMap)); + this.flashMapManager.setFlashMaps(List.of(flashMap)); this.request.setRequestURI("/path"); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response); @@ -71,7 +72,7 @@ public class FlashMapManagerTests { flashMap.put("key", "value"); flashMap.setTargetRequestPath("/accounts"); - this.flashMapManager.setFlashMaps(Arrays.asList(flashMap)); + this.flashMapManager.setFlashMaps(List.of(flashMap)); this.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/accounts"); this.request.setRequestURI("/mvc/accounts"); @@ -82,12 +83,12 @@ public class FlashMapManagerTests { } @Test - public void retrieveAndUpdateMatchWithTrailingSlash() { + void retrieveAndUpdateMatchWithTrailingSlash() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/path"); - this.flashMapManager.setFlashMaps(Arrays.asList(flashMap)); + this.flashMapManager.setFlashMaps(List.of(flashMap)); this.request.setRequestURI("/path/"); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response); @@ -97,12 +98,12 @@ public class FlashMapManagerTests { } @Test - public void retrieveAndUpdateMatchByParams() { + void retrieveAndUpdateMatchByParams() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.addTargetRequestParam("number", "one"); - this.flashMapManager.setFlashMaps(Arrays.asList(flashMap)); + this.flashMapManager.setFlashMaps(List.of(flashMap)); this.request.setQueryString("number="); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response); @@ -130,7 +131,7 @@ public class FlashMapManagerTests { flashMap.addTargetRequestParam("id", "1"); flashMap.addTargetRequestParam("id", "2"); - this.flashMapManager.setFlashMaps(Arrays.asList(flashMap)); + this.flashMapManager.setFlashMaps(List.of(flashMap)); this.request.setQueryString("id=1"); FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response); @@ -146,7 +147,7 @@ public class FlashMapManagerTests { } @Test - public void retrieveAndUpdateSortMultipleMatches() { + void retrieveAndUpdateSortMultipleMatches() { FlashMap emptyFlashMap = new FlashMap(); FlashMap flashMapOne = new FlashMap(); @@ -168,7 +169,7 @@ public class FlashMapManagerTests { } @Test - public void retrieveAndUpdateRemoveExpired() { + void retrieveAndUpdateRemoveExpired() { List flashMaps = new ArrayList<>(); for (int i = 0; i < 5; i++) { FlashMap expiredFlashMap = new FlashMap(); @@ -183,7 +184,7 @@ public class FlashMapManagerTests { } @Test - public void saveOutputFlashMapEmpty() { + void saveOutputFlashMapEmpty() { FlashMap flashMap = new FlashMap(); this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response); @@ -193,7 +194,7 @@ public class FlashMapManagerTests { } @Test - public void saveOutputFlashMap() { + void saveOutputFlashMap() { FlashMap flashMap = new FlashMap(); flashMap.put("name", "value"); @@ -207,7 +208,7 @@ public class FlashMapManagerTests { } @Test - public void saveOutputFlashMapDecodeTargetPath() { + void saveOutputFlashMapDecodeTargetPath() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); @@ -218,7 +219,7 @@ public class FlashMapManagerTests { } @Test - public void saveOutputFlashMapNormalizeTargetPath() { + void saveOutputFlashMapNormalizeTargetPath() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); @@ -265,7 +266,7 @@ public class FlashMapManagerTests { } @Test // SPR-9657, SPR-11504 - public void saveOutputFlashMapDecodeParameters() throws Exception { + public void saveOutputFlashMapDecodeParameters() { FlashMap flashMap = new FlashMap(); flashMap.put("key", "value"); flashMap.setTargetRequestPath("/path"); @@ -292,7 +293,7 @@ public class FlashMapManagerTests { } @Test // SPR-12569 - public void flashAttributesWithQueryParamsWithSpace() throws Exception { + public void flashAttributesWithQueryParamsWithSpace() { String encodedValue = URLEncoder.encode("1 2", StandardCharsets.UTF_8); FlashMap flashMap = new FlashMap(); @@ -333,7 +334,7 @@ public class FlashMapManagerTests { } - private static ObjectAssert assertThatFlashMap(FlashMap flashMap) { + private static ObjectAssert assertThatFlashMap(@Nullable FlashMap flashMap) { return assertThat((Object) flashMap); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/RequestContextTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/RequestContextTests.java index 84e38ed346d..c92bef79c3c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/RequestContextTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/RequestContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer * @author Rossen Stoyanchev */ -public class RequestContextTests { +class RequestContextTests { private MockHttpServletRequest request = new MockHttpServletRequest(); @@ -46,21 +46,21 @@ public class RequestContextTests { private Map model = new HashMap<>(); @BeforeEach - public void init() { + void init() { GenericWebApplicationContext applicationContext = new GenericWebApplicationContext(); applicationContext.refresh(); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); } @Test - public void testGetContextUrl() throws Exception { + void testGetContextUrl() { request.setContextPath("foo/"); RequestContext context = new RequestContext(request, response, servletContext, model); assertThat(context.getContextUrl("bar")).isEqualTo("foo/bar"); } @Test - public void testGetContextUrlWithMap() throws Exception { + void testGetContextUrlWithMap() { request.setContextPath("foo/"); RequestContext context = new RequestContext(request, response, servletContext, model); Map map = new HashMap<>(); @@ -70,7 +70,7 @@ public class RequestContextTests { } @Test - public void testGetContextUrlWithMapEscaping() throws Exception { + void testGetContextUrlWithMapEscaping() { request.setContextPath("foo/"); RequestContext context = new RequestContext(request, response, servletContext, model); Map map = new HashMap<>(); @@ -80,7 +80,7 @@ public class RequestContextTests { } @Test - public void testPathToServlet() throws Exception { + void testPathToServlet() { request.setContextPath("/app"); request.setServletPath("/servlet"); RequestContext context = new RequestContext(request, response, servletContext, model); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/ServletUriComponentsBuilderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/ServletUriComponentsBuilderTests.java index 2eeef16a686..3c161b25a40 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/ServletUriComponentsBuilderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/ServletUriComponentsBuilderTests.java @@ -35,13 +35,13 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rossen Stoyanchev */ -public class ServletUriComponentsBuilderTests { +class ServletUriComponentsBuilderTests { private MockHttpServletRequest request; @BeforeEach - public void setup() { + void setup() { this.request = new MockHttpServletRequest(); this.request.setScheme("http"); this.request.setServerName("localhost"); @@ -52,7 +52,7 @@ public class ServletUriComponentsBuilderTests { @Test - public void fromRequest() { + void fromRequest() { this.request.setRequestURI("/mvc-showcase/data/param"); this.request.setQueryString("foo=123"); String result = ServletUriComponentsBuilder.fromRequest(this.request).build().toUriString(); @@ -60,21 +60,21 @@ public class ServletUriComponentsBuilderTests { } @Test - public void fromRequestEncodedPath() { + void fromRequestEncodedPath() { this.request.setRequestURI("/mvc-showcase/data/foo%20bar"); String result = ServletUriComponentsBuilder.fromRequest(this.request).build().toUriString(); assertThat(result).isEqualTo("http://localhost/mvc-showcase/data/foo%20bar"); } @Test - public void fromRequestAtypicalHttpPort() { + void fromRequestAtypicalHttpPort() { this.request.setServerPort(8080); String result = ServletUriComponentsBuilder.fromRequest(this.request).build().toUriString(); assertThat(result).isEqualTo("http://localhost:8080/mvc-showcase"); } @Test - public void fromRequestAtypicalHttpsPort() { + void fromRequestAtypicalHttpsPort() { this.request.setScheme("https"); this.request.setServerPort(9043); String result = ServletUriComponentsBuilder.fromRequest(this.request).build().toUriString(); @@ -84,7 +84,7 @@ public class ServletUriComponentsBuilderTests { // Some X-Forwarded-* tests in addition to the ones in UriComponentsBuilderTests @Test - public void fromRequestWithForwardedHostAndPort() throws Exception { + void fromRequestWithForwardedHostAndPort() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); @@ -101,7 +101,7 @@ public class ServletUriComponentsBuilderTests { } @Test - public void fromRequestUri() { + void fromRequestUri() { this.request.setRequestURI("/mvc-showcase/data/param"); this.request.setQueryString("foo=123"); String result = ServletUriComponentsBuilder.fromRequestUri(this.request).build().toUriString(); @@ -145,7 +145,7 @@ public class ServletUriComponentsBuilderTests { } @Test - public void fromContextPath() { + void fromContextPath() { this.request.setRequestURI("/mvc-showcase/data/param"); this.request.setQueryString("foo=123"); String result = ServletUriComponentsBuilder.fromContextPath(this.request).build().toUriString(); @@ -165,7 +165,7 @@ public class ServletUriComponentsBuilderTests { } @Test - public void fromServletMapping() { + void fromServletMapping() { this.request.setRequestURI("/mvc-showcase/app/simple"); this.request.setServletPath("/app"); this.request.setQueryString("foo=123"); @@ -187,7 +187,7 @@ public class ServletUriComponentsBuilderTests { } @Test - public void fromCurrentRequest() { + void fromCurrentRequest() { this.request.setRequestURI("/mvc-showcase/data/param"); this.request.setQueryString("foo=123"); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request)); @@ -210,7 +210,7 @@ public class ServletUriComponentsBuilderTests { } @Test - public void pathExtensionNone() { + void pathExtensionNone() { this.request.setRequestURI("/rest/books/6"); ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(this.request); assertThat(builder.removePathExtension()).isNull(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/WebContentGeneratorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/WebContentGeneratorTests.java index f2fecf78b57..43efcda039d 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/WebContentGeneratorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/WebContentGeneratorTests.java @@ -28,42 +28,42 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link WebContentGenerator}. * @author Rossen Stoyanchev */ -public class WebContentGeneratorTests { +class WebContentGeneratorTests { @Test - public void getAllowHeaderWithConstructorTrue() throws Exception { + void getAllowHeaderWithConstructorTrue() { WebContentGenerator generator = new TestWebContentGenerator(true); assertThat(generator.getAllowHeader()).isEqualTo("GET,HEAD,POST,OPTIONS"); } @Test - public void getAllowHeaderWithConstructorFalse() throws Exception { + void getAllowHeaderWithConstructorFalse() { WebContentGenerator generator = new TestWebContentGenerator(false); assertThat(generator.getAllowHeader()).isEqualTo("GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS"); } @Test - public void getAllowHeaderWithSupportedMethodsConstructor() throws Exception { + void getAllowHeaderWithSupportedMethodsConstructor() { WebContentGenerator generator = new TestWebContentGenerator("POST"); assertThat(generator.getAllowHeader()).isEqualTo("POST,OPTIONS"); } @Test - public void getAllowHeaderWithSupportedMethodsSetter() throws Exception { + void getAllowHeaderWithSupportedMethodsSetter() { WebContentGenerator generator = new TestWebContentGenerator(); generator.setSupportedMethods("POST"); assertThat(generator.getAllowHeader()).isEqualTo("POST,OPTIONS"); } @Test - public void getAllowHeaderWithSupportedMethodsSetterEmpty() throws Exception { + void getAllowHeaderWithSupportedMethodsSetterEmpty() { WebContentGenerator generator = new TestWebContentGenerator(); generator.setSupportedMethods(); assertThat(generator.getAllowHeader()).as("Effectively \"no restriction\" on supported methods").isEqualTo("GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS"); } @Test - public void varyHeaderNone() throws Exception { + void varyHeaderNone() { WebContentGenerator generator = new TestWebContentGenerator(); MockHttpServletResponse response = new MockHttpServletResponse(); generator.prepareResponse(response); @@ -72,7 +72,7 @@ public class WebContentGeneratorTests { } @Test - public void varyHeader() throws Exception { + void varyHeader() { String[] configuredValues = {"Accept-Language", "User-Agent"}; String[] responseValues = {}; String[] expected = {"Accept-Language", "User-Agent"}; @@ -80,7 +80,7 @@ public class WebContentGeneratorTests { } @Test - public void varyHeaderWithExistingWildcard() throws Exception { + void varyHeaderWithExistingWildcard() { String[] configuredValues = {"Accept-Language"}; String[] responseValues = {"*"}; String[] expected = {"*"}; @@ -88,7 +88,7 @@ public class WebContentGeneratorTests { } @Test - public void varyHeaderWithExistingCommaValues() throws Exception { + void varyHeaderWithExistingCommaValues() { String[] configuredValues = {"Accept-Language", "User-Agent"}; String[] responseValues = {"Accept-Encoding", "Accept-Language"}; String[] expected = {"Accept-Encoding", "Accept-Language", "User-Agent"}; @@ -96,7 +96,7 @@ public class WebContentGeneratorTests { } @Test - public void varyHeaderWithExistingCommaSeparatedValues() throws Exception { + void varyHeaderWithExistingCommaSeparatedValues() { String[] configuredValues = {"Accept-Language", "User-Agent"}; String[] responseValues = {"Accept-Encoding, Accept-Language"}; String[] expected = {"Accept-Encoding, Accept-Language", "User-Agent"}; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ArgumentTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ArgumentTagTests.java index 03b8ec13401..0288642bed0 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ArgumentTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ArgumentTagTests.java @@ -33,14 +33,14 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Nicholas Williams */ -public class ArgumentTagTests extends AbstractTagTests { +class ArgumentTagTests extends AbstractTagTests { private ArgumentTag tag; private MockArgumentSupportTag parent; @BeforeEach - public void setUp() throws Exception { + void setUp() { PageContext context = createPageContext(); parent = new MockArgumentSupportTag(); tag = new ArgumentTag(); @@ -49,7 +49,7 @@ public class ArgumentTagTests extends AbstractTagTests { } @Test - public void argumentWithStringValue() throws JspException { + void argumentWithStringValue() throws JspException { tag.setValue("value1"); int action = tag.doEndTag(); @@ -59,7 +59,7 @@ public class ArgumentTagTests extends AbstractTagTests { } @Test - public void argumentWithImplicitNullValue() throws JspException { + void argumentWithImplicitNullValue() throws JspException { int action = tag.doEndTag(); assertThat(action).isEqualTo(Tag.EVAL_PAGE); @@ -67,7 +67,7 @@ public class ArgumentTagTests extends AbstractTagTests { } @Test - public void argumentWithExplicitNullValue() throws JspException { + void argumentWithExplicitNullValue() throws JspException { tag.setValue(null); int action = tag.doEndTag(); @@ -77,7 +77,7 @@ public class ArgumentTagTests extends AbstractTagTests { } @Test - public void argumentWithBodyValue() throws JspException { + void argumentWithBodyValue() throws JspException { tag.setBodyContent(new MockBodyContent("value2", new MockHttpServletResponse())); @@ -88,7 +88,7 @@ public class ArgumentTagTests extends AbstractTagTests { } @Test - public void argumentWithValueThenReleaseThenBodyValue() throws JspException { + void argumentWithValueThenReleaseThenBodyValue() throws JspException { tag.setValue("value3"); int action = tag.doEndTag(); @@ -111,7 +111,7 @@ public class ArgumentTagTests extends AbstractTagTests { } @SuppressWarnings("serial") - private class MockArgumentSupportTag extends TagSupport implements ArgumentAware { + private static class MockArgumentSupportTag extends TagSupport implements ArgumentAware { Object argument; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagOutsideDispatcherServletTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagOutsideDispatcherServletTests.java index 3149d0494ee..63188a0854b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagOutsideDispatcherServletTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagOutsideDispatcherServletTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2024 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. @@ -20,7 +20,7 @@ package org.springframework.web.servlet.tags; * @author Juergen Hoeller * @since 14.01.2005 */ -public class BindTagOutsideDispatcherServletTests extends BindTagTests { +class BindTagOutsideDispatcherServletTests extends BindTagTests { @Override protected boolean inDispatcherServlet() { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagTests.java index b20ae009b72..5886e0b6fd1 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -624,7 +624,7 @@ class BindTagTests extends AbstractTagTests { } @Test - void bindTagWithoutBean() throws JspException { + void bindTagWithoutBean() { PageContext pc = createPageContext(); BindTag tag = new BindTag(); tag.setPageContext(pc); @@ -886,7 +886,7 @@ class BindTagTests extends AbstractTagTests { } @Test - void transformTagOutsideBindTag() throws JspException { + void transformTagOutsideBindTag() { // first set up the pagecontext and the bean PageContext pc = createPageContext(); TestBean tb = new TestBean(); @@ -994,11 +994,7 @@ class BindTagTests extends AbstractTagTests { assertThat(pc.getAttribute("theString")).isEqualTo("name"); } - /** - * SPR-4022 - */ - @SuppressWarnings("serial") - @Test + @Test // SPR-4022 void nestingInFormTag() throws JspException { PageContext pc = createPageContext(); TestBean tb = new TestBean(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java index a2405234257..400f92abcfa 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Keith Donald */ -public class EvalTagTests extends AbstractTagTests { +class EvalTagTests extends AbstractTagTests { private EvalTag tag; @@ -48,7 +48,7 @@ public class EvalTagTests extends AbstractTagTests { @BeforeEach - public void setup() throws Exception { + void setup() { context = createPageContext(); FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean(); factory.afterPropertiesSet(); @@ -60,7 +60,7 @@ public class EvalTagTests extends AbstractTagTests { @Test - public void printScopedAttributeResult() throws Exception { + void printScopedAttributeResult() throws Exception { tag.setExpression("bean.method()"); int action = tag.doStartTag(); assertThat(action).isEqualTo(Tag.EVAL_BODY_INCLUDE); @@ -70,7 +70,7 @@ public class EvalTagTests extends AbstractTagTests { } @Test - public void printNullAsEmptyString() throws Exception { + void printNullAsEmptyString() throws Exception { tag.setExpression("bean.null"); int action = tag.doStartTag(); assertThat(action).isEqualTo(Tag.EVAL_BODY_INCLUDE); @@ -80,7 +80,7 @@ public class EvalTagTests extends AbstractTagTests { } @Test - public void printFormattedScopedAttributeResult() throws Exception { + void printFormattedScopedAttributeResult() throws Exception { PercentStyleFormatter formatter = new PercentStyleFormatter(); tag.setExpression("bean.formattable"); int action = tag.doStartTag(); @@ -91,7 +91,7 @@ public class EvalTagTests extends AbstractTagTests { } @Test - public void printHtmlEscapedAttributeResult() throws Exception { + void printHtmlEscapedAttributeResult() throws Exception { tag.setExpression("bean.html()"); tag.setHtmlEscape(true); int action = tag.doStartTag(); @@ -102,7 +102,7 @@ public class EvalTagTests extends AbstractTagTests { } @Test - public void printJavaScriptEscapedAttributeResult() throws Exception { + void printJavaScriptEscapedAttributeResult() throws Exception { tag.setExpression("bean.js()"); tag.setJavaScriptEscape(true); int action = tag.doStartTag(); @@ -113,7 +113,7 @@ public class EvalTagTests extends AbstractTagTests { } @Test - public void setFormattedScopedAttributeResult() throws Exception { + void setFormattedScopedAttributeResult() throws Exception { tag.setExpression("bean.formattable"); tag.setVar("foo"); int action = tag.doStartTag(); @@ -135,7 +135,7 @@ public class EvalTagTests extends AbstractTagTests { } @Test - public void accessUsingBeanSyntax() throws Exception { + void accessUsingBeanSyntax() throws Exception { GenericApplicationContext wac = (GenericApplicationContext) context.getRequest().getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE); wac.getDefaultListableBeanFactory().registerSingleton("bean2", context.getRequest().getAttribute("bean")); @@ -149,7 +149,7 @@ public class EvalTagTests extends AbstractTagTests { } @Test - public void environmentAccess() throws Exception { + void environmentAccess() throws Exception { Map map = new HashMap<>(); map.put("key.foo", "value.foo"); GenericApplicationContext wac = (GenericApplicationContext) @@ -165,7 +165,7 @@ public class EvalTagTests extends AbstractTagTests { } @Test - public void mapAccess() throws Exception { + void mapAccess() throws Exception { tag.setExpression("bean.map.key"); int action = tag.doStartTag(); assertThat(action).isEqualTo(Tag.EVAL_BODY_INCLUDE); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/HtmlEscapeTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/HtmlEscapeTagTests.java index f02f45737ee..0a35d25a47f 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/HtmlEscapeTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/HtmlEscapeTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -31,7 +31,6 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Juergen Hoeller * @author Alef Arendsen */ -@SuppressWarnings("serial") class HtmlEscapeTagTests extends AbstractTagTests { @Test @@ -42,7 +41,7 @@ class HtmlEscapeTagTests extends AbstractTagTests { tag.doStartTag(); HtmlEscapingAwareTag testTag = new HtmlEscapingAwareTag() { @Override - public int doStartTagInternal() throws Exception { + public int doStartTagInternal() { return EVAL_BODY_INCLUDE; } }; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/MessageTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/MessageTagTests.java index 34b63cc4d59..ec7122ea522 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/MessageTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/MessageTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -39,7 +39,6 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Alef Arendsen * @author Nicholas Williams */ -@SuppressWarnings("serial") class MessageTagTests extends AbstractTagTests { @Test diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTagTests.java index f3ae95f9735..0be73bef4c8 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTagTests.java @@ -35,21 +35,21 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Scott Andrews * @author Nicholas Williams */ -public class ParamTagTests extends AbstractTagTests { +class ParamTagTests extends AbstractTagTests { private final ParamTag tag = new ParamTag(); private MockParamSupportTag parent = new MockParamSupportTag(); @BeforeEach - public void setUp() throws Exception { + void setUp() { PageContext context = createPageContext(); tag.setPageContext(context); tag.setParent(parent); } @Test - public void paramWithNameAndValue() throws JspException { + void paramWithNameAndValue() throws JspException { tag.setName("name"); tag.setValue("value"); @@ -61,7 +61,7 @@ public class ParamTagTests extends AbstractTagTests { } @Test - public void paramWithBodyValue() throws JspException { + void paramWithBodyValue() throws JspException { tag.setName("name"); tag.setBodyContent(new MockBodyContent("value", new MockHttpServletResponse())); @@ -73,7 +73,7 @@ public class ParamTagTests extends AbstractTagTests { } @Test - public void paramWithImplicitNullValue() throws JspException { + void paramWithImplicitNullValue() throws JspException { tag.setName("name"); int action = tag.doEndTag(); @@ -84,7 +84,7 @@ public class ParamTagTests extends AbstractTagTests { } @Test - public void paramWithExplicitNullValue() throws JspException { + void paramWithExplicitNullValue() throws JspException { tag.setName("name"); tag.setValue(null); @@ -96,7 +96,7 @@ public class ParamTagTests extends AbstractTagTests { } @Test - public void paramWithValueThenReleaseThenBodyValue() throws JspException { + void paramWithValueThenReleaseThenBodyValue() throws JspException { tag.setName("name1"); tag.setValue("value1"); @@ -122,7 +122,7 @@ public class ParamTagTests extends AbstractTagTests { } @Test - public void paramWithNoParent() throws Exception { + void paramWithNoParent() { tag.setName("name"); tag.setValue("value"); tag.setParent(null); @@ -131,7 +131,7 @@ public class ParamTagTests extends AbstractTagTests { } @SuppressWarnings("serial") - private class MockParamSupportTag extends TagSupport implements ParamAware { + private static class MockParamSupportTag extends TagSupport implements ParamAware { private Param param; diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTests.java index 0dabe36aefd..e334308af8b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTests.java @@ -25,24 +25,24 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Scott Andrews */ -public class ParamTests { +class ParamTests { private final Param param = new Param(); @Test - public void name() { + void name() { param.setName("name"); assertThat(param.getName()).isEqualTo("name"); } @Test - public void value() { + void value() { param.setValue("value"); assertThat(param.getValue()).isEqualTo("value"); } @Test - public void nullDefaults() { + void nullDefaults() { assertThat(param.getName()).isNull(); assertThat(param.getValue()).isNull(); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ThemeTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ThemeTagTests.java index df5b390b31c..ef6a455ffa4 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ThemeTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ThemeTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,8 @@ package org.springframework.web.servlet.tags; -import java.util.Arrays; import java.util.List; -import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.PageContext; @@ -40,7 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat; class ThemeTagTests extends AbstractTagTests { @Test - @SuppressWarnings("serial") void themeTag() throws JspException { PageContext pc = createPageContext(); final StringBuilder message = new StringBuilder(); @@ -59,7 +56,7 @@ class ThemeTagTests extends AbstractTagTests { @Test @SuppressWarnings("rawtypes") - void requestContext() throws ServletException { + void requestContext() { PageContext pc = createPageContext(); RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest()); assertThat(rc.getThemeMessage("themetest")).isEqualTo("theme test message"); @@ -67,7 +64,7 @@ class ThemeTagTests extends AbstractTagTests { assertThat(rc.getThemeMessage("themetest", "default")).isEqualTo("theme test message"); assertThat(rc.getThemeMessage("themetest", (Object[]) null, "default")).isEqualTo("theme test message"); assertThat(rc.getThemeMessage("themetestArgs", new String[]{"arg1"})).isEqualTo("theme test message arg1"); - assertThat(rc.getThemeMessage("themetestArgs", Arrays.asList(new String[]{"arg1"}))).isEqualTo("theme test message arg1"); + assertThat(rc.getThemeMessage("themetestArgs", List.of("arg1"))).isEqualTo("theme test message arg1"); assertThat(rc.getThemeMessage("themetesta", "default")).isEqualTo("default"); assertThat(rc.getThemeMessage("themetesta", (List) null, "default")).isEqualTo("default"); MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"}); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/UrlTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/UrlTagTests.java index c04199f372a..da3125e3e9e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/UrlTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/UrlTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Scott Andrews */ -public class UrlTagTests extends AbstractTagTests { +class UrlTagTests extends AbstractTagTests { private UrlTag tag; @@ -43,7 +43,7 @@ public class UrlTagTests extends AbstractTagTests { @BeforeEach - public void setup() throws Exception { + void setup() { context = createPageContext(); tag = new UrlTag(); tag.setPageContext(context); @@ -51,19 +51,19 @@ public class UrlTagTests extends AbstractTagTests { @Test - public void paramSupport() { + void paramSupport() { assertThat(tag).isInstanceOf(ParamAware.class); } @Test - public void doStartTag() throws JspException { + void doStartTag() throws JspException { int action = tag.doStartTag(); assertThat(action).isEqualTo(Tag.EVAL_BODY_INCLUDE); } @Test - public void doEndTag() throws JspException { + void doEndTag() throws JspException { tag.setValue("url/path"); tag.doStartTag(); int action = tag.doEndTag(); @@ -72,7 +72,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void varDefaultScope() throws JspException { + void varDefaultScope() throws JspException { tag.setValue("url/path"); tag.setVar("var"); tag.doStartTag(); @@ -82,7 +82,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void varExplicitScope() throws JspException { + void varExplicitScope() throws JspException { tag.setValue("url/path"); tag.setVar("var"); tag.setScope("request"); @@ -93,7 +93,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void setHtmlEscapeDefault() throws JspException { + void setHtmlEscapeDefault() throws JspException { tag.setValue("url/path"); tag.setVar("var"); tag.doStartTag(); @@ -113,7 +113,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void setHtmlEscapeFalse() throws JspException { + void setHtmlEscapeFalse() throws JspException { tag.setValue("url/path"); tag.setVar("var"); tag.setHtmlEscape(false); @@ -135,7 +135,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void setHtmlEscapeTrue() throws JspException { + void setHtmlEscapeTrue() throws JspException { tag.setValue("url/path"); tag.setVar("var"); tag.setHtmlEscape(true); @@ -156,7 +156,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void setJavaScriptEscapeTrue() throws JspException { + void setJavaScriptEscapeTrue() throws JspException { tag.setValue("url/path"); tag.setVar("var"); tag.setJavaScriptEscape(true); @@ -177,7 +177,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void setHtmlAndJavaScriptEscapeTrue() throws JspException { + void setHtmlAndJavaScriptEscapeTrue() throws JspException { tag.setValue("url/path"); tag.setVar("var"); tag.setHtmlEscape(true); @@ -199,7 +199,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createQueryStringNoParams() throws JspException { + void createQueryStringNoParams() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -208,7 +208,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createQueryStringOneParam() throws JspException { + void createQueryStringOneParam() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -222,7 +222,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createQueryStringOneParamForExistingQueryString() throws JspException { + void createQueryStringOneParamForExistingQueryString() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -236,7 +236,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createQueryStringOneParamEmptyValue() throws JspException { + void createQueryStringOneParamEmptyValue() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -250,7 +250,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createQueryStringOneParamNullValue() throws JspException { + void createQueryStringOneParamNullValue() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -264,7 +264,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createQueryStringOneParamAlreadyUsed() throws JspException { + void createQueryStringOneParamAlreadyUsed() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -279,7 +279,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createQueryStringTwoParams() throws JspException { + void createQueryStringTwoParams() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -298,7 +298,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createQueryStringUrlEncoding() throws JspException { + void createQueryStringUrlEncoding() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -317,7 +317,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createQueryStringParamNullName() throws JspException { + void createQueryStringParamNullName() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -331,7 +331,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createQueryStringParamEmptyName() throws JspException { + void createQueryStringParamEmptyName() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -345,7 +345,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void replaceUriTemplateParamsNoParams() throws JspException { + void replaceUriTemplateParamsNoParams() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -355,7 +355,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void replaceUriTemplateParamsTemplateWithoutParamMatch() throws JspException { + void replaceUriTemplateParamsTemplateWithoutParamMatch() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -365,7 +365,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void replaceUriTemplateParamsTemplateWithParamMatch() throws JspException { + void replaceUriTemplateParamsTemplateWithParamMatch() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -381,7 +381,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void replaceUriTemplateParamsTemplateWithParamMatchNamePreEncoding() throws JspException { + void replaceUriTemplateParamsTemplateWithParamMatchNamePreEncoding() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -397,7 +397,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void replaceUriTemplateParamsTemplateWithParamMatchValueEncoded() throws JspException { + void replaceUriTemplateParamsTemplateWithParamMatchValueEncoded() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -432,7 +432,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void replaceUriTemplateParamsTemplateWithPath() throws JspException { + void replaceUriTemplateParamsTemplateWithPath() throws JspException { List params = new ArrayList<>(); Set usedParams = new HashSet<>(); @@ -448,7 +448,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createUrlRemoteServer() throws JspException { + void createUrlRemoteServer() throws JspException { tag.setValue("https://www.springframework.org/"); tag.doStartTag(); @@ -457,7 +457,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createUrlRelative() throws JspException { + void createUrlRelative() throws JspException { tag.setValue("url/path"); tag.doStartTag(); @@ -466,7 +466,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createUrlLocalContext() throws JspException { + void createUrlLocalContext() throws JspException { ((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context"); tag.setValue("/url/path"); @@ -477,7 +477,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createUrlRemoteContext() throws JspException { + void createUrlRemoteContext() throws JspException { ((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context"); tag.setValue("/url/path"); @@ -489,7 +489,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createUrlRemoteContextWithSlash() throws JspException { + void createUrlRemoteContextWithSlash() throws JspException { ((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context"); tag.setValue("/url/path"); @@ -501,7 +501,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createUrlRemoteContextSingleSlash() throws JspException { + void createUrlRemoteContextSingleSlash() throws JspException { ((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context"); tag.setValue("/url/path"); @@ -513,7 +513,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createUrlWithParams() throws JspException { + void createUrlWithParams() throws JspException { tag.setValue("url/path"); tag.doStartTag(); @@ -532,7 +532,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createUrlWithTemplateParams() throws JspException { + void createUrlWithTemplateParams() throws JspException { tag.setValue("url/{name}"); tag.doStartTag(); @@ -551,7 +551,7 @@ public class UrlTagTests extends AbstractTagTests { } @Test - public void createUrlWithParamAndExistingQueryString() throws JspException { + void createUrlWithParamAndExistingQueryString() throws JspException { tag.setValue("url/path?foo=bar"); tag.doStartTag(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ButtonTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ButtonTagTests.java index 39c03e587ac..c8cf7c4a39b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ButtonTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/ButtonTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,7 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Rossen Stoyanchev */ -public class ButtonTagTests extends AbstractFormTagTests { +class ButtonTagTests extends AbstractFormTagTests { private ButtonTag tag; @@ -43,7 +43,7 @@ public class ButtonTagTests extends AbstractFormTagTests { } @Test - public void buttonTag() throws Exception { + void buttonTag() throws Exception { assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE); assertThat(this.tag.doEndTag()).isEqualTo(Tag.EVAL_PAGE); @@ -59,7 +59,7 @@ public class ButtonTagTests extends AbstractFormTagTests { } @Test - public void disabled() throws Exception { + void disabled() throws Exception { this.tag.setDisabled(true); this.tag.doStartTag(); @@ -85,7 +85,6 @@ public class ButtonTagTests extends AbstractFormTagTests { assertThat(output).as("Tag not opened properly").startsWith("