Skip to content

Commit c01f45f

Browse files
committed
Fix failing test
1 parent f8e1f06 commit c01f45f

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.web.servlet.config.annotation;
1818

1919
import java.util.ArrayList;
20+
import java.util.Collections;
2021
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
@@ -321,8 +322,11 @@ public HandlerMapping resourceHandlerMapping() {
321322
*/
322323
@Bean
323324
public ResourceUrlGenerator resourceUrlGenerator() {
324-
SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) resourceHandlerMapping();
325-
return new ResourceUrlGenerator(hm.getUrlMap());
325+
Map<String, ?> handlerMap = Collections.<String, Object>emptyMap();
326+
if (resourceHandlerMapping() instanceof SimpleUrlHandlerMapping) {
327+
handlerMap = ((SimpleUrlHandlerMapping) resourceHandlerMapping()).getUrlMap();
328+
}
329+
return new ResourceUrlGenerator(handlerMap);
326330
}
327331

328332
/**

spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceUrlFilterTests.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.web.servlet.resource;
1818

1919
import java.util.ArrayList;
20-
import java.util.Collections;
2120
import java.util.List;
2221

2322
import javax.servlet.ServletException;
@@ -26,7 +25,6 @@
2625
import javax.servlet.http.HttpServletResponse;
2726

2827
import org.junit.Test;
29-
import org.springframework.context.annotation.Bean;
3028
import org.springframework.context.annotation.Configuration;
3129
import org.springframework.mock.web.test.MockFilterChain;
3230
import org.springframework.mock.web.test.MockHttpServletRequest;
@@ -36,7 +34,6 @@
3634
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
3735
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
3836
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
39-
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
4037

4138
import static org.junit.Assert.*;
4239

@@ -120,6 +117,7 @@ private void initFilterChain(Class<?> configClass) throws ServletException {
120117
@Configuration
121118
static class WebConfig extends WebMvcConfigurationSupport {
122119

120+
123121
@Override
124122
public void addResourceHandlers(ResourceHandlerRegistry registry) {
125123

@@ -131,14 +129,6 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
131129
.addResourceLocations("classpath:org/springframework/web/servlet/resource/test/")
132130
.setResourceResolvers(resourceResolvers);
133131
}
134-
135-
@Bean
136-
public ResourceUrlGenerator resourceUrlGenerator() {
137-
ResourceUrlGenerator generator = new ResourceUrlGenerator();
138-
SimpleUrlHandlerMapping handlerMapping = (SimpleUrlHandlerMapping) resourceHandlerMapping();
139-
generator.setResourceHandlerMappings(Collections.singletonList(handlerMapping));
140-
return generator;
141-
}
142132
}
143133

144134
private static class TestServlet extends HttpServlet {

0 commit comments

Comments
 (0)