@@ -50,7 +50,6 @@ public class FormContentFilterTests {
50
50
@ Before
51
51
public void setup () {
52
52
this .request = new MockHttpServletRequest ("PUT" , "/" );
53
- this .request .addHeader ("Content-Type" , "application/x-www-form-urlencoded; charset=ISO-8859-1" );
54
53
this .request .setContentType ("application/x-www-form-urlencoded; charset=ISO-8859-1" );
55
54
this .response = new MockHttpServletResponse ();
56
55
this .filterChain = new MockFilterChain ();
@@ -59,29 +58,31 @@ public void setup() {
59
58
60
59
@ Test
61
60
public void wrapPutPatchAndDeleteOnly () throws Exception {
62
- this .request .setContent ("foo=bar" .getBytes ("ISO-8859-1" ));
63
61
for (HttpMethod method : HttpMethod .values ()) {
64
- this .request .setMethod (method .name ());
62
+ MockHttpServletRequest request = new MockHttpServletRequest (method .name (), "/" );
63
+ request .setContent ("foo=bar" .getBytes ("ISO-8859-1" ));
64
+ request .setContentType ("application/x-www-form-urlencoded; charset=ISO-8859-1" );
65
65
this .filterChain = new MockFilterChain ();
66
- this .filter .doFilter (this . request , this .response , this .filterChain );
66
+ this .filter .doFilter (request , this .response , this .filterChain );
67
67
if (method == HttpMethod .PUT || method == HttpMethod .PATCH || method == HttpMethod .DELETE ) {
68
- assertNotSame (this . request , this .filterChain .getRequest ());
68
+ assertNotSame (request , this .filterChain .getRequest ());
69
69
}
70
70
else {
71
- assertSame (this . request , this .filterChain .getRequest ());
71
+ assertSame (request , this .filterChain .getRequest ());
72
72
}
73
73
}
74
74
}
75
75
76
76
@ Test
77
77
public void wrapFormEncodedOnly () throws Exception {
78
- this .request .setContent ("" .getBytes ("ISO-8859-1" ));
79
78
String [] contentTypes = new String [] {"text/plain" , "multipart/form-data" };
80
79
for (String contentType : contentTypes ) {
81
- this .request .setContentType (contentType );
80
+ MockHttpServletRequest request = new MockHttpServletRequest ("PUT" , "/" );
81
+ request .setContent ("" .getBytes ("ISO-8859-1" ));
82
+ request .setContentType (contentType );
82
83
this .filterChain = new MockFilterChain ();
83
- this .filter .doFilter (this . request , this .response , this .filterChain );
84
- assertSame (this . request , this .filterChain .getRequest ());
84
+ this .filter .doFilter (request , this .response , this .filterChain );
85
+ assertSame (request , this .filterChain .getRequest ());
85
86
}
86
87
}
87
88
@@ -146,7 +147,7 @@ public void getParameterValues() throws Exception {
146
147
String [] values = this .filterChain .getRequest ().getParameterValues ("name" );
147
148
148
149
assertNotSame ("Request not wrapped" , this .request , filterChain .getRequest ());
149
- assertArrayEquals (new String []{"value1" , "value2" , "value3" , "value4" }, values );
150
+ assertArrayEquals (new String [] {"value1" , "value2" , "value3" , "value4" }, values );
150
151
}
151
152
152
153
@ Test
@@ -160,7 +161,7 @@ public void getParameterValuesFromQueryString() throws Exception {
160
161
String [] values = this .filterChain .getRequest ().getParameterValues ("name" );
161
162
162
163
assertNotSame ("Request not wrapped" , this .request , this .filterChain .getRequest ());
163
- assertArrayEquals (new String []{"value1" , "value2" }, values );
164
+ assertArrayEquals (new String [] {"value1" , "value2" }, values );
164
165
}
165
166
166
167
@ Test
@@ -173,7 +174,7 @@ public void getParameterValuesFromFormContent() throws Exception {
173
174
String [] values = this .filterChain .getRequest ().getParameterValues ("anotherName" );
174
175
175
176
assertNotSame ("Request not wrapped" , this .request , this .filterChain .getRequest ());
176
- assertArrayEquals (new String []{"anotherValue" }, values );
177
+ assertArrayEquals (new String [] {"anotherValue" }, values );
177
178
}
178
179
179
180
@ Test
@@ -211,7 +212,7 @@ public void hiddenHttpMethodFilterFollowedByHttpPutFormContentFilter() throws Ex
211
212
this .request .addParameter ("hiddenField" , "testHidden" );
212
213
this .filter .doFilter (this .request , this .response , this .filterChain );
213
214
214
- assertArrayEquals (new String []{"testHidden" },
215
+ assertArrayEquals (new String [] {"testHidden" },
215
216
this .filterChain .getRequest ().getParameterValues ("hiddenField" ));
216
217
}
217
218
0 commit comments