This commit is contained in:
Stéphane Nicoll 2024-01-11 16:59:04 +01:00
parent f067ff862b
commit ee04442be7
169 changed files with 1558 additions and 1674 deletions

View File

@ -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",

View File

@ -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();

View File

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

View File

@ -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();

View File

@ -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<String, Object> 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<String> 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<String> 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<String> 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<String> paths = new HashSet<>();
paths.add("C:/webroot/WEB-INF/context1.xml");
paths.add("C:/webroot/WEB-INF/context2.xml");

View File

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

View File

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

View File

@ -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() {

View File

@ -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<String, String> 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<String, String> params = new LinkedMultiValueMap<>();
params.add(" ", "abc");
params.add(null, " ");

View File

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

View File

@ -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();

View File

@ -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();

View File

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

View File

@ -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();

View File

@ -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())

View File

@ -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("/**");

View File

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

View File

@ -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<HandlerExceptionResolver> resolvers) {
@ -272,7 +272,7 @@ public class DelegatingWebMvcConfigurationTests {
}
@Test
public void configurePathPatternParser() {
void configurePathPatternParser() {
PathPatternParser patternParser = new PathPatternParser();
PathMatcher pathMatcher = mock();
UrlPathHelper pathHelper = mock();

View File

@ -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<HandlerInterceptor> 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<HandlerInterceptor> 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<HandlerInterceptor> 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<HandlerInterceptor> 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) {
}
}

View File

@ -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<ResourceResolver> 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<ResourceTransformer> 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();

View File

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

View File

@ -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("<html><body>Hello World!</body></html>");
}
@Test
public void groovyMarkup() throws Exception {
void groovyMarkup() throws Exception {
MockHttpServletResponse response = runTest(GroovyMarkupWebConfig.class);
assertThat(response.getContentAsString()).isEqualTo("<html><body>Hello World!</body></html>");
}
@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("<html><body>Hello World!</body></html>");
}

View File

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

View File

@ -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.
*
* <p>
* 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<HandlerExceptionResolver> 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<String, CorsConfiguration> 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 {
}

View File

@ -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<String, HandlerMapping> 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<HttpMessageConverter<?>> 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,

View File

@ -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<Map<String, Object>> nestedAttributes = new LinkedList<>();
private final Deque<Map<String, Object>> nestedAttributes = new LinkedList<>();
private final List<List<Map<String, Object>>> routerFunctionsAttributes = new LinkedList<>();
@Nullable
private Map<String, Object> attributes;
private List<List<Map<String, Object>>> routerFunctionsAttributes = new LinkedList<>();
private int visitCount;
public List<List<Map<String, Object>>> routerFunctionsAttributes() {
@ -66,7 +65,7 @@ class AttributesTestVisitor implements RouterFunctions.Visitor {
public void route(RequestPredicate predicate, HandlerFunction<?> handlerFunction) {
Stream<Map<String, Object>> current = Optional.ofNullable(attributes).stream();
Stream<Map<String, Object>> nested = nestedAttributes.stream().filter(Objects::nonNull);
routerFunctionsAttributes.add(Stream.concat(current, nested).collect(Collectors.toUnmodifiableList()));
routerFunctionsAttributes.add(Stream.concat(current, nested).toList());
attributes = null;
}

View File

@ -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<String> entityResponse = EntityResponse.fromObject("bar")
.lastModified(oneMinuteBeforeNow)

View File

@ -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<String, String> 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<String, Cookie> 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))

View File

@ -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<String> 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());

View File

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

View File

@ -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"));

View File

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

View File

@ -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<ServerResponse> route = RouterFunctions.route()
.GET("/error", request -> {
throw new IOException();
@ -237,7 +237,7 @@ class RouterFunctionBuilderTests {
}
@Test
public void attributes() {
void attributes() {
RouterFunction<ServerResponse> route = RouterFunctions.route()
.GET("/atts/1", request -> ServerResponse.ok().build())
.withAttribute("foo", "bar")

View File

@ -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<ServerResponse> route = RouterFunctions.route(
GET("/atts/1"), request -> ServerResponse.ok().build())
.withAttribute("foo", "bar")

View File

@ -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<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RequestPredicate requestPredicate = mock();
@ -54,7 +54,7 @@ public class RouterFunctionsTests {
}
@Test
public void routeNoMatch() {
void routeNoMatch() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RequestPredicate requestPredicate = mock();
@ -68,7 +68,7 @@ public class RouterFunctionsTests {
}
@Test
public void nestMatch() {
void nestMatch() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = request -> Optional.of(handlerFunction);
@ -84,7 +84,7 @@ public class RouterFunctionsTests {
}
@Test
public void nestNoMatch() {
void nestNoMatch() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = request -> Optional.of(handlerFunction);
@ -99,7 +99,7 @@ public class RouterFunctionsTests {
}
@Test
public void nestPathVariable() {
void nestPathVariable() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RequestPredicate requestPredicate = request -> request.pathVariable("foo").equals("bar");
RouterFunction<ServerResponse> nestedFunction = RouterFunctions.route(requestPredicate, handlerFunction);
@ -115,7 +115,7 @@ public class RouterFunctionsTests {
}
@Test
public void composedPathVariable() {
void composedPathVariable() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RequestPredicate requestPredicate = RequestPredicates.path("/{foo}").and(
request -> request.pathVariable("foo").equals("bar"));

View File

@ -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()));

View File

@ -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() {

View File

@ -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<String> 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<String> 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<String> {
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<String> matches = new ArrayList<>();

View File

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

View File

@ -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");

View File

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

View File

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

View File

@ -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();

View File

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

View File

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

View File

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

View File

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

View File

@ -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(() ->

View File

@ -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");

View File

@ -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");

View File

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

View File

@ -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/");

View File

@ -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");

View File

@ -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(() ->

View File

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

View File

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

View File

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

View File

@ -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();

View File

@ -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<GenericWebApplicationContext> initializer)

View File

@ -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<String> 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<String> future = new CompletableFuture<>();
testHandle(future, CompletableFuture.class, () -> future.complete("foo"), "foo");
}
@Test
public void deferredResultWithError() throws Exception {
void deferredResultWithError() throws Exception {
DeferredResult<String> 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<String> future = new CompletableFuture<>();
IllegalStateException ex = new IllegalStateException();
testHandle(future, CompletableFuture.class, () -> future.completeExceptionally(ex), ex);

View File

@ -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<String, String> 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<String, String> 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);

View File

@ -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<String> stringHttpMessageConverter = mock();
@SuppressWarnings("unchecked")
private HttpMessageConverter<Resource> resourceMessageConverter = mock();
@SuppressWarnings("unchecked")
private HttpMessageConverter<Object> resourceRegionMessageConverter = mock();
@SuppressWarnings("unchecked")
private HttpMessageConverter<Object> 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<String> 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<String> 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<String> returnValue = new ResponseEntity<>("Body", HttpStatus.ACCEPTED);
servletRequest.addHeader("Accept", "01");
@ -474,7 +469,7 @@ class HttpEntityMethodProcessorMockTests {
ArgumentCaptor<HttpOutputMessage> 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<String> returnValue = ResponseEntity.ok()
.lastModified(justModified).body("body");
initStringMessageConversion(TEXT_PLAIN);

View File

@ -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<HttpMessageConverter<?>> 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<HttpMessageConverter<?>> 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<HttpMessageConverter<?>> 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) {

View File

@ -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<String, String> 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<String, String> 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<String, String> params2 = getVariablesFor("planes");
params2.add("colors", "yellow");
params2.add("colors", "orange");

View File

@ -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<String, String> 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<String, String> params = getVariablesFor("cars");
params.add("anotherYear", "2012");
MethodParameter param = this.testMethod.annot(matrixAttribute().name("year")).arg(int.class);

View File

@ -74,7 +74,7 @@ import static org.mockito.Mockito.mock;
* </ul>
* @author Rossen Stoyanchev
*/
public class MethodValidationTests {
class MethodValidationTests {
private static final Person mockPerson = mock(Person.class);

View File

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

View File

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

View File

@ -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() {

View File

@ -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<String, String> uriTemplateVars = new HashMap<>();
uriTemplateVars.put("name1", "value1");
uriTemplateVars.put("name2", "value2");

View File

@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> 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);

View File

@ -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<String> sink = Sinks.one();
@ -178,7 +177,7 @@ public class ReactiveTypeHandlerTests {
}
@Test
public void deferredResultSubscriberWithNoValues() throws Exception {
void deferredResultSubscriberWithNoValues() throws Exception {
Sinks.One<String> 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<String> -> List<String> 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<String> 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<Bar> 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<Bar> sink = Sinks.many().unicast().onBackpressureBuffer();
@ -357,7 +356,7 @@ public class ReactiveTypeHandlerTests {
}
@Test
public void writeText() throws Exception {
void writeText() throws Exception {
Sinks.Many<String> 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<ResponseBodyEmitter.DataWithMediaType> items) throws IOException {
public void send(Set<ResponseBodyEmitter.DataWithMediaType> items) {
items.forEach(item -> this.values.add(item.getData()));
}

View File

@ -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() {

View File

@ -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<String> handleHttpEntity(HttpEntity<byte[]> httpEntity) throws Exception {
String responseBody = "Handled requestBody=[" + new String(httpEntity.getBody(), "UTF-8") + "]";
public ResponseEntity<String> handleHttpEntity(HttpEntity<byte[]> httpEntity) {
String responseBody = "Handled requestBody=[" + new String(httpEntity.getBody(), StandardCharsets.UTF_8) + "]";
return ResponseEntity.accepted()
.header("header", "headerValue")
.body(responseBody);
}
public ResponseEntity<String> handleHttpEntityWithCacheControl(HttpEntity<byte[]> httpEntity) throws Exception {
String responseBody = "Handled requestBody=[" + new String(httpEntity.getBody(), "UTF-8") + "]";
public ResponseEntity<String> handleHttpEntityWithCacheControl(HttpEntity<byte[]> 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());
}

View File

@ -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();

View File

@ -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<Arguments> pathPatternsArguments() {
@ -353,12 +353,10 @@ public class RequestMappingHandlerMappingTests {
assertThat(info).isNotNull();
Set<String> paths = info.getPatternValues();
assertThat(paths).hasSize(1);
assertThat(paths).element(0).isEqualTo(path);
assertThat(paths).containsExactly(path);
Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
assertThat(methods).hasSize(1);
assertThat(methods).element(0).isEqualTo(requestMethod);
assertThat(methods).containsExactly(requestMethod);
return info;
}

View File

@ -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<String, String> params = Collections.singletonMap("boundary", boundaryText);

View File

@ -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<SimpleBean> 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();

View File

@ -68,7 +68,6 @@ class RequestResponseBodyAdviceChainTests {
@Test
@SuppressWarnings("unchecked")
void requestBodyAdvice() throws IOException {
RequestBodyAdvice requestAdvice = mock();
ResponseBodyAdvice<String> responseAdvice = mock();
@ -91,7 +90,6 @@ class RequestResponseBodyAdviceChainTests {
}
@Test
@SuppressWarnings("unchecked")
void responseBodyAdvice() {
RequestBodyAdvice requestAdvice = mock();
ResponseBodyAdvice<String> responseAdvice = mock();

View File

@ -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<String> stringMessageConverter = mock();
@SuppressWarnings("unchecked")
private HttpMessageConverter<Resource> resourceMessageConverter = mock();
@SuppressWarnings("unchecked")
private HttpMessageConverter<Object> 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();

View File

@ -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<Object> entity =
testException(new HttpRequestMethodNotSupportedException("GET", List.of("POST", "DELETE")));
@ -122,7 +122,7 @@ public class ResponseEntityExceptionHandlerTests {
}
@Test
public void httpMediaTypeNotSupported() {
void httpMediaTypeNotSupported() {
ResponseEntity<Object> 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);

View File

@ -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<TestBean> testBeans = (List<TestBean>) 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<TestBean> testBeans = (List<TestBean>) 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);
}
}

View File

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

View File

@ -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<HttpMessageConverter<?>> 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<HttpMessageConverter<?>> 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");
}
}

View File

@ -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<String, String> 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<String, String> 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(

View File

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

View File

@ -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();

View File

@ -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() {

View File

@ -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<ResponseBodyEmitter.DataWithMediaType> items) throws IOException {
public void send(Set<ResponseBodyEmitter.DataWithMediaType> items) {
for (ResponseBodyEmitter.DataWithMediaType item : items) {
this.objects.add(item.getData());
this.mediaTypes.add(item.getMediaType());

View File

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

View File

@ -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");

View File

@ -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<Boolean> 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<String, Object> 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));

View File

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

View File

@ -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:*");

View File

@ -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() {

View File

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

View File

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

View File

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

View File

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

View File

@ -47,17 +47,15 @@ public class EncodedResourceResolverTests {
private List<Resource> 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<ResourceResolver> 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);

Some files were not shown because too many files have changed in this diff Show More