Skip to content

Commit 5f765fc

Browse files
committed
Polishing
1 parent 6b456b6 commit 5f765fc

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java

+32-32
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import org.springframework.context.annotation.Configuration;
2626
import org.springframework.stereotype.Controller;
2727
import org.springframework.ui.ModelMap;
28-
import org.springframework.web.bind.annotation.RequestMapping;
29-
import org.springframework.web.bind.annotation.RequestMethod;
28+
import org.springframework.web.bind.annotation.GetMapping;
3029
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
3130
import org.springframework.web.servlet.DispatcherServlet;
3231
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
@@ -48,16 +47,25 @@
4847
*/
4948
class ViewResolutionIntegrationTests {
5049

50+
private static final String EXPECTED_BODY = "<html><body>Hello World!</body></html>";
51+
52+
5153
@Test
5254
void freemarker() throws Exception {
5355
MockHttpServletResponse response = runTest(FreeMarkerWebConfig.class);
54-
assertThat(response.getContentAsString()).isEqualTo("<html><body>Hello World!</body></html>");
56+
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
57+
}
58+
59+
@Test // SPR-12013
60+
void freemarkerWithExistingViewResolver() throws Exception {
61+
MockHttpServletResponse response = runTest(ExistingViewResolverConfig.class);
62+
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
5563
}
5664

5765
@Test
5866
void groovyMarkup() throws Exception {
5967
MockHttpServletResponse response = runTest(GroovyMarkupWebConfig.class);
60-
assertThat(response.getContentAsString()).isEqualTo("<html><body>Hello World!</body></html>");
68+
assertThat(response.getContentAsString()).isEqualTo(EXPECTED_BODY);
6169
}
6270

6371
@Test
@@ -74,14 +82,6 @@ void groovyMarkupInvalidConfig() {
7482
.withMessageContaining("In addition to a Groovy markup view resolver ");
7583
}
7684

77-
// SPR-12013
78-
79-
@Test
80-
void existingViewResolver() throws Exception {
81-
MockHttpServletResponse response = runTest(ExistingViewResolverConfig.class);
82-
assertThat(response.getContentAsString()).isEqualTo("<html><body>Hello World!</body></html>");
83-
}
84-
8585

8686
private MockHttpServletResponse runTest(Class<?> configClass) throws ServletException, IOException {
8787
String basePath = "org/springframework/web/servlet/config/annotation";
@@ -104,7 +104,7 @@ private MockHttpServletResponse runTest(Class<?> configClass) throws ServletExce
104104
@Controller
105105
static class SampleController {
106106

107-
@RequestMapping(value = "/", method = RequestMethod.GET)
107+
@GetMapping
108108
public String sample(ModelMap model) {
109109
model.addAttribute("hello", "Hello World!");
110110
return "index";
@@ -136,6 +136,25 @@ public FreeMarkerConfigurer freeMarkerConfigurer() {
136136
}
137137
}
138138

139+
/**
140+
* Test @EnableWebMvc in the presence of a pre-existing ViewResolver.
141+
*/
142+
@Configuration
143+
static class ExistingViewResolverConfig extends AbstractWebConfig {
144+
145+
@Bean
146+
public FreeMarkerViewResolver freeMarkerViewResolver() {
147+
return new FreeMarkerViewResolver("", ".ftl");
148+
}
149+
150+
@Bean
151+
public FreeMarkerConfigurer freeMarkerConfigurer() {
152+
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
153+
configurer.setTemplateLoaderPath("/WEB-INF/");
154+
return configurer;
155+
}
156+
}
157+
139158
@Configuration
140159
static class GroovyMarkupWebConfig extends AbstractWebConfig {
141160

@@ -170,23 +189,4 @@ public void configureViewResolvers(ViewResolverRegistry registry) {
170189
}
171190
}
172191

173-
/**
174-
* Test @EnableWebMvc in the presence of pre-existing ViewResolver.
175-
*/
176-
@Configuration
177-
static class ExistingViewResolverConfig extends AbstractWebConfig {
178-
179-
@Bean
180-
public FreeMarkerViewResolver freeMarkerViewResolver() {
181-
return new FreeMarkerViewResolver("", ".ftl");
182-
}
183-
184-
@Bean
185-
public FreeMarkerConfigurer freeMarkerConfigurer() {
186-
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
187-
configurer.setTemplateLoaderPath("/WEB-INF/");
188-
return configurer;
189-
}
190-
}
191-
192192
}

0 commit comments

Comments
 (0)