|
16 | 16 |
|
17 | 17 | package org.springframework.web.method.annotation;
|
18 | 18 |
|
19 |
| -import static org.junit.Assert.assertArrayEquals; |
20 |
| -import static org.junit.Assert.assertEquals; |
21 |
| -import static org.junit.Assert.assertFalse; |
22 |
| -import static org.junit.Assert.assertNull; |
23 |
| -import static org.junit.Assert.assertTrue; |
24 |
| -import static org.junit.Assert.fail; |
25 |
| - |
26 | 19 | import java.lang.reflect.Method;
|
27 | 20 | import java.util.Arrays;
|
28 | 21 | import java.util.List;
|
|
32 | 25 |
|
33 | 26 | import org.junit.Before;
|
34 | 27 | import org.junit.Test;
|
| 28 | +import org.springframework.beans.propertyeditors.StringTrimmerEditor; |
35 | 29 | import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
36 | 30 | import org.springframework.core.MethodParameter;
|
37 | 31 | import org.springframework.core.ParameterNameDiscoverer;
|
|
41 | 35 | import org.springframework.mock.web.test.MockMultipartHttpServletRequest;
|
42 | 36 | import org.springframework.mock.web.test.MockPart;
|
43 | 37 | import org.springframework.web.bind.MissingServletRequestParameterException;
|
| 38 | +import org.springframework.web.bind.WebDataBinder; |
44 | 39 | import org.springframework.web.bind.annotation.RequestParam;
|
45 | 40 | import org.springframework.web.bind.annotation.RequestPart;
|
| 41 | +import org.springframework.web.bind.support.WebDataBinderFactory; |
| 42 | +import org.springframework.web.bind.support.WebRequestDataBinder; |
46 | 43 | import org.springframework.web.context.request.NativeWebRequest;
|
47 | 44 | import org.springframework.web.context.request.ServletWebRequest;
|
48 | 45 | import org.springframework.web.multipart.MultipartException;
|
49 | 46 | import org.springframework.web.multipart.MultipartFile;
|
50 | 47 |
|
| 48 | +import static org.junit.Assert.*; |
| 49 | +import static org.mockito.BDDMockito.*; |
| 50 | +import static org.mockito.Mockito.*; |
| 51 | + |
51 | 52 | /**
|
52 | 53 | * Test fixture with {@link org.springframework.web.method.annotation.RequestParamMethodArgumentResolver}.
|
53 | 54 | *
|
@@ -242,6 +243,23 @@ public void missingRequestParam() throws Exception {
|
242 | 243 | fail("Expected exception");
|
243 | 244 | }
|
244 | 245 |
|
| 246 | + // SPR-10402 |
| 247 | + |
| 248 | + @Test(expected = MissingServletRequestParameterException.class) |
| 249 | + public void missingRequestParamEmptyValueConvertedToNull() throws Exception { |
| 250 | + |
| 251 | + WebDataBinder binder = new WebRequestDataBinder(null); |
| 252 | + binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); |
| 253 | + |
| 254 | + WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class); |
| 255 | + given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder); |
| 256 | + |
| 257 | + this.request.addParameter("stringNotAnnot", ""); |
| 258 | + |
| 259 | + resolver.resolveArgument(paramStringNotAnnot, null, webRequest, binderFactory); |
| 260 | + fail("Expected exception"); |
| 261 | + } |
| 262 | + |
245 | 263 | @Test
|
246 | 264 | public void resolveSimpleTypeParam() throws Exception {
|
247 | 265 | request.setParameter("stringNotAnnot", "plainValue");
|
|
0 commit comments