Skip to content

Commit 67f0b19

Browse files
committed
Consistent spelling for StandaloneMockMvcBuilder's addPlaceholderValue
(cherry picked from commit a4b6682)
1 parent 60e0177 commit 67f0b19

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -119,7 +119,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
119119

120120
private Boolean removeSemicolonContent;
121121

122-
private Map<String, String> placeHolderValues = new HashMap<String, String>();
122+
private Map<String, String> placeholderValues = new HashMap<String, String>();
123123

124124

125125
/**
@@ -317,9 +317,19 @@ public StandaloneMockMvcBuilder setRemoveSemicolonContent(boolean removeSemicolo
317317
* request mappings. This method allows manually provided placeholder values so they
318318
* can be resolved. Alternatively consider creating a test that initializes a
319319
* {@link WebApplicationContext}.
320+
* @since 4.2.8
320321
*/
322+
public StandaloneMockMvcBuilder addPlaceholderValue(String name, String value) {
323+
this.placeholderValues.put(name, value);
324+
return this;
325+
}
326+
327+
/**
328+
* @deprecated as of 4.2.8, in favor of {@link #addPlaceholderValue(String, String)}
329+
*/
330+
@Deprecated
321331
public StandaloneMockMvcBuilder addPlaceHolderValue(String name, String value) {
322-
this.placeHolderValues.put(name, value);
332+
this.placeholderValues.put(name, value);
323333
return this;
324334
}
325335

@@ -364,8 +374,8 @@ private void registerMvcSingletons(StubWebApplicationContext wac) {
364374
}
365375

366376
private List<ViewResolver> initViewResolvers(WebApplicationContext wac) {
367-
this.viewResolvers = (this.viewResolvers == null) ?
368-
Arrays.<ViewResolver>asList(new InternalResourceViewResolver()) : this.viewResolvers;
377+
this.viewResolvers = (this.viewResolvers != null ? this.viewResolvers :
378+
Collections.<ViewResolver>singletonList(new InternalResourceViewResolver()));
369379
for (Object viewResolver : this.viewResolvers) {
370380
if (viewResolver instanceof WebApplicationObjectSupport) {
371381
((WebApplicationObjectSupport) viewResolver).setApplicationContext(wac);
@@ -380,7 +390,7 @@ private class StandaloneConfiguration extends WebMvcConfigurationSupport {
380390

381391
public StaticRequestMappingHandlerMapping getHandlerMapping() {
382392
StaticRequestMappingHandlerMapping handlerMapping = new StaticRequestMappingHandlerMapping();
383-
handlerMapping.setEmbeddedValueResolver(new StaticStringValueResolver(placeHolderValues));
393+
handlerMapping.setEmbeddedValueResolver(new StaticStringValueResolver(placeholderValues));
384394
handlerMapping.setUseSuffixPatternMatch(useSuffixPatternMatch);
385395
handlerMapping.setUseTrailingSlashMatch(useTrailingSlashPatternMatch);
386396
handlerMapping.setOrder(0);
@@ -440,8 +450,8 @@ public Validator mvcValidator() {
440450
try {
441451
((InitializingBean) mvcValidator).afterPropertiesSet();
442452
}
443-
catch (Exception e) {
444-
throw new BeanInitializationException("Failed to initialize Validator", e);
453+
catch (Exception ex) {
454+
throw new BeanInitializationException("Failed to initialize Validator", ex);
445455
}
446456
}
447457
return mvcValidator;

spring-test/src/test/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilderTests.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@
2323
import javax.servlet.http.HttpServletRequest;
2424
import javax.servlet.http.HttpServletResponse;
2525

26+
import com.fasterxml.jackson.databind.JsonSerializer;
27+
import com.fasterxml.jackson.databind.ser.impl.UnknownSerializer;
2628
import org.junit.Test;
2729

2830
import org.springframework.http.converter.json.SpringHandlerInstantiator;
@@ -36,9 +38,6 @@
3638
import org.springframework.web.servlet.HandlerExecutionChain;
3739
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
3840

39-
import com.fasterxml.jackson.databind.JsonSerializer;
40-
import com.fasterxml.jackson.databind.ser.impl.UnknownSerializer;
41-
4241
import static org.junit.Assert.*;
4342

4443
/**
@@ -50,12 +49,10 @@
5049
*/
5150
public class StandaloneMockMvcBuilderTests {
5251

53-
// SPR-10825
54-
55-
@Test
52+
@Test // SPR-10825
5653
public void placeHoldersInRequestMapping() throws Exception {
5754
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
58-
builder.addPlaceHolderValue("sys.login.ajax", "/foo");
55+
builder.addPlaceholderValue("sys.login.ajax", "/foo");
5956
builder.build();
6057

6158
RequestMappingHandlerMapping hm = builder.wac.getBean(RequestMappingHandlerMapping.class);
@@ -67,9 +64,7 @@ public void placeHoldersInRequestMapping() throws Exception {
6764
assertEquals("handleWithPlaceholders", ((HandlerMethod) chain.getHandler()).getMethod().getName());
6865
}
6966

70-
// SPR-13637
71-
72-
@Test
67+
@Test // SPR-13637
7368
public void suffixPatternMatch() throws Exception {
7469
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
7570
builder.setUseSuffixPatternMatch(false);
@@ -87,18 +82,15 @@ public void suffixPatternMatch() throws Exception {
8782
assertNull(chain);
8883
}
8984

90-
// SPR-12553
91-
92-
@Test
85+
@Test // SPR-12553
9386
public void applicationContextAttribute() {
9487
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
95-
builder.addPlaceHolderValue("sys.login.ajax", "/foo");
88+
builder.addPlaceholderValue("sys.login.ajax", "/foo");
9689
WebApplicationContext wac = builder.initWebAppContext();
9790
assertEquals(wac, WebApplicationContextUtils
9891
.getRequiredWebApplicationContext(wac.getServletContext()));
9992
}
10093

101-
10294
@Test(expected = IllegalArgumentException.class)
10395
public void addFiltersFiltersNull() {
10496
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
@@ -123,9 +115,7 @@ public void addFilterPatternContainsNull() {
123115
builder.addFilter(new ContinueFilter(), (String) null);
124116
}
125117

126-
// SPR-13375
127-
128-
@Test
118+
@Test // SPR-13375
129119
@SuppressWarnings("rawtypes")
130120
public void springHandlerInstantiator() {
131121
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
@@ -159,6 +149,7 @@ protected WebApplicationContext initWebAppContext() {
159149
}
160150
}
161151

152+
162153
@Controller
163154
private static class PersonController {
164155

@@ -173,6 +164,7 @@ public String forward() {
173164
}
174165
}
175166

167+
176168
private class ContinueFilter extends OncePerRequestFilter {
177169

178170
@Override

0 commit comments

Comments
 (0)