1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .web .servlet .support ;
18
18
19
- import static org .junit .Assert .*;
20
-
21
19
import java .net .URLEncoder ;
22
20
import java .util .ArrayList ;
23
21
import java .util .Arrays ;
24
22
import java .util .Collections ;
25
23
import java .util .List ;
26
24
import java .util .concurrent .CopyOnWriteArrayList ;
27
-
28
25
import javax .servlet .http .HttpServletRequest ;
29
26
import javax .servlet .http .HttpServletResponse ;
30
27
31
- import org .junit .Before ;
32
28
import org .junit .Test ;
33
29
34
30
import org .springframework .mock .web .test .MockHttpServletRequest ;
35
31
import org .springframework .mock .web .test .MockHttpServletResponse ;
36
32
import org .springframework .web .servlet .FlashMap ;
37
33
import org .springframework .web .util .WebUtils ;
38
34
35
+ import static org .junit .Assert .*;
39
36
40
37
/**
41
38
* Test fixture for testing {@link AbstractFlashMapManager} methods.
42
39
*
43
40
* @author Rossen Stoyanchev
41
+ * @author Sam Brannen
44
42
*/
45
43
public class FlashMapManagerTests {
46
44
47
- private TestFlashMapManager flashMapManager ;
48
-
49
- private MockHttpServletRequest request ;
45
+ private final TestFlashMapManager flashMapManager = new TestFlashMapManager ();
50
46
51
- private MockHttpServletResponse response ;
47
+ private final MockHttpServletRequest request = new MockHttpServletRequest () ;
52
48
53
-
54
- @ Before
55
- public void setup () {
56
- this .flashMapManager = new TestFlashMapManager ();
57
- this .request = new MockHttpServletRequest ();
58
- this .response = new MockHttpServletResponse ();
59
- }
49
+ private final MockHttpServletResponse response = new MockHttpServletResponse ();
60
50
61
51
62
52
@ Test
@@ -73,9 +63,7 @@ public void retrieveAndUpdateMatchByPath() {
73
63
assertEquals (flashMap , inputFlashMap );
74
64
}
75
65
76
- // SPR-8779
77
-
78
- @ Test
66
+ @ Test // SPR-8779
79
67
public void retrieveAndUpdateMatchByOriginatingPath () {
80
68
FlashMap flashMap = new FlashMap ();
81
69
flashMap .put ("key" , "value" );
@@ -133,9 +121,7 @@ public void retrieveAndUpdateMatchByParams() {
133
121
assertEquals ("Input FlashMap should have been removed" , 0 , this .flashMapManager .getFlashMaps ().size ());
134
122
}
135
123
136
- // SPR-8798
137
-
138
- @ Test
124
+ @ Test // SPR-8798
139
125
public void retrieveAndUpdateMatchWithMultiValueParam () {
140
126
FlashMap flashMap = new FlashMap ();
141
127
flashMap .put ("name" , "value" );
@@ -180,7 +166,7 @@ public void retrieveAndUpdateSortMultipleMatches() {
180
166
}
181
167
182
168
@ Test
183
- public void retrieveAndUpdateRemoveExpired () throws InterruptedException {
169
+ public void retrieveAndUpdateRemoveExpired () {
184
170
List <FlashMap > flashMaps = new ArrayList <>();
185
171
for (int i = 0 ; i < 5 ; i ++) {
186
172
FlashMap expiredFlashMap = new FlashMap ();
@@ -195,7 +181,7 @@ public void retrieveAndUpdateRemoveExpired() throws InterruptedException {
195
181
}
196
182
197
183
@ Test
198
- public void saveOutputFlashMapEmpty () throws InterruptedException {
184
+ public void saveOutputFlashMapEmpty () {
199
185
FlashMap flashMap = new FlashMap ();
200
186
201
187
this .flashMapManager .saveOutputFlashMap (flashMap , this .request , this .response );
@@ -205,7 +191,7 @@ public void saveOutputFlashMapEmpty() throws InterruptedException {
205
191
}
206
192
207
193
@ Test
208
- public void saveOutputFlashMap () throws InterruptedException {
194
+ public void saveOutputFlashMap () {
209
195
FlashMap flashMap = new FlashMap ();
210
196
flashMap .put ("name" , "value" );
211
197
@@ -219,7 +205,7 @@ public void saveOutputFlashMap() throws InterruptedException {
219
205
}
220
206
221
207
@ Test
222
- public void saveOutputFlashMapDecodeTargetPath () throws InterruptedException {
208
+ public void saveOutputFlashMapDecodeTargetPath () {
223
209
FlashMap flashMap = new FlashMap ();
224
210
flashMap .put ("key" , "value" );
225
211
@@ -230,7 +216,7 @@ public void saveOutputFlashMapDecodeTargetPath() throws InterruptedException {
230
216
}
231
217
232
218
@ Test
233
- public void saveOutputFlashMapNormalizeTargetPath () throws InterruptedException {
219
+ public void saveOutputFlashMapNormalizeTargetPath () {
234
220
FlashMap flashMap = new FlashMap ();
235
221
flashMap .put ("key" , "value" );
236
222
@@ -265,11 +251,19 @@ public void saveOutputFlashMapNormalizeTargetPath() throws InterruptedException
265
251
assertEquals ("/once/only" , flashMap .getTargetRequestPath ());
266
252
}
267
253
268
- // SPR-9657, SPR-11504
254
+ @ Test // gh-23240
255
+ public void saveOutputFlashMapAndNormalizeEmptyTargetPath () {
256
+ FlashMap flashMap = new FlashMap ();
257
+ flashMap .put ("key" , "value" );
269
258
270
- @ Test
271
- public void saveOutputFlashMapDecodeParameters () throws Exception {
259
+ flashMap . setTargetRequestPath ( "" );
260
+ this . flashMapManager . saveOutputFlashMap ( flashMap , this . request , this . response );
272
261
262
+ assertEquals ("" , flashMap .getTargetRequestPath ());
263
+ }
264
+
265
+ @ Test // SPR-9657, SPR-11504
266
+ public void saveOutputFlashMapDecodeParameters () throws Exception {
273
267
FlashMap flashMap = new FlashMap ();
274
268
flashMap .put ("key" , "value" );
275
269
flashMap .setTargetRequestPath ("/path" );
@@ -295,11 +289,8 @@ public void saveOutputFlashMapDecodeParameters() throws Exception {
295
289
assertEquals ("value" , flashMap .get ("key" ));
296
290
}
297
291
298
- // SPR-12569
299
-
300
- @ Test
292
+ @ Test // SPR-12569
301
293
public void flashAttributesWithQueryParamsWithSpace () throws Exception {
302
-
303
294
String encodedValue = URLEncoder .encode ("1 2" , "UTF-8" );
304
295
305
296
FlashMap flashMap = new FlashMap ();
0 commit comments