@@ -53,109 +53,107 @@ public class InterceptorRegistryTests {
53
53
54
54
private final HandlerInterceptor interceptor2 = new ThemeChangeInterceptor ();
55
55
56
- private TestWebRequestInterceptor webRequestInterceptor1 ;
56
+ private TestWebRequestInterceptor webInterceptor1 ;
57
57
58
- private TestWebRequestInterceptor webRequestInterceptor2 ;
58
+ private TestWebRequestInterceptor webInterceptor2 ;
59
59
60
60
private final MockHttpServletRequest request = new MockHttpServletRequest ();
61
61
62
62
private final MockHttpServletResponse response = new MockHttpServletResponse ();
63
63
64
+
64
65
@ Before
65
66
public void setUp () {
66
- registry = new InterceptorRegistry ();
67
- webRequestInterceptor1 = new TestWebRequestInterceptor ();
68
- webRequestInterceptor2 = new TestWebRequestInterceptor ();
67
+ this . registry = new InterceptorRegistry ();
68
+ this . webInterceptor1 = new TestWebRequestInterceptor ();
69
+ this . webInterceptor2 = new TestWebRequestInterceptor ();
69
70
}
70
71
71
72
@ Test
72
73
public void addInterceptor () {
73
- registry .addInterceptor (interceptor1 );
74
+ this . registry .addInterceptor (this . interceptor1 );
74
75
List <HandlerInterceptor > interceptors = getInterceptorsForPath (null );
75
-
76
- assertEquals (Arrays .asList (interceptor1 ), interceptors );
76
+ assertEquals (Arrays .asList (this .interceptor1 ), interceptors );
77
77
}
78
78
79
79
@ Test
80
80
public void addTwoInterceptors () {
81
- registry .addInterceptor (interceptor1 );
82
- registry .addInterceptor (interceptor2 );
81
+ this . registry .addInterceptor (this . interceptor1 );
82
+ this . registry .addInterceptor (this . interceptor2 );
83
83
List <HandlerInterceptor > interceptors = getInterceptorsForPath (null );
84
-
85
- assertEquals (Arrays .asList (interceptor1 , interceptor2 ), interceptors );
84
+ assertEquals (Arrays .asList (this .interceptor1 , this .interceptor2 ), interceptors );
86
85
}
87
86
88
87
@ Test
89
88
public void addInterceptorsWithUrlPatterns () {
90
- registry .addInterceptor (interceptor1 ).addPathPatterns ("/path1/**" ).excludePathPatterns ("/path1/secret" );
91
- registry .addInterceptor (interceptor2 ).addPathPatterns ("/path2" );
89
+ this . registry .addInterceptor (this . interceptor1 ).addPathPatterns ("/path1/**" ).excludePathPatterns ("/path1/secret" );
90
+ this . registry .addInterceptor (this . interceptor2 ).addPathPatterns ("/path2" );
92
91
93
- assertEquals (Arrays .asList (interceptor1 ), getInterceptorsForPath ("/path1" ));
94
- assertEquals (Arrays .asList (interceptor2 ), getInterceptorsForPath ("/path2" ));
92
+ assertEquals (Arrays .asList (this . interceptor1 ), getInterceptorsForPath ("/path1" ));
93
+ assertEquals (Arrays .asList (this . interceptor2 ), getInterceptorsForPath ("/path2" ));
95
94
assertEquals (Collections .emptyList (), getInterceptorsForPath ("/path1/secret" ));
96
95
}
97
96
98
97
@ Test
99
98
public void addWebRequestInterceptor () throws Exception {
100
- registry .addWebRequestInterceptor (webRequestInterceptor1 );
99
+ this . registry .addWebRequestInterceptor (this . webInterceptor1 );
101
100
List <HandlerInterceptor > interceptors = getInterceptorsForPath (null );
102
101
103
102
assertEquals (1 , interceptors .size ());
104
- verifyAdaptedInterceptor (interceptors .get (0 ), webRequestInterceptor1 );
103
+ verifyWebInterceptor (interceptors .get (0 ), this . webInterceptor1 );
105
104
}
106
105
107
106
@ Test
108
107
public void addWebRequestInterceptors () throws Exception {
109
- registry .addWebRequestInterceptor (webRequestInterceptor1 );
110
- registry .addWebRequestInterceptor (webRequestInterceptor2 );
108
+ this . registry .addWebRequestInterceptor (this . webInterceptor1 );
109
+ this . registry .addWebRequestInterceptor (this . webInterceptor2 );
111
110
List <HandlerInterceptor > interceptors = getInterceptorsForPath (null );
112
111
113
112
assertEquals (2 , interceptors .size ());
114
- verifyAdaptedInterceptor (interceptors .get (0 ), webRequestInterceptor1 );
115
- verifyAdaptedInterceptor (interceptors .get (1 ), webRequestInterceptor2 );
113
+ verifyWebInterceptor (interceptors .get (0 ), this . webInterceptor1 );
114
+ verifyWebInterceptor (interceptors .get (1 ), this . webInterceptor2 );
116
115
}
117
116
118
117
@ Test
119
118
public void addInterceptorsWithCustomPathMatcher () {
120
119
PathMatcher pathMatcher = Mockito .mock (PathMatcher .class );
121
- registry .addInterceptor (interceptor1 ).addPathPatterns ("/path1/**" ).pathMatcher (pathMatcher );
120
+ this . registry .addInterceptor (interceptor1 ).addPathPatterns ("/path1/**" ).pathMatcher (pathMatcher );
122
121
123
- MappedInterceptor mappedInterceptor = (MappedInterceptor ) registry .getInterceptors ().get (0 );
122
+ MappedInterceptor mappedInterceptor = (MappedInterceptor ) this . registry .getInterceptors ().get (0 );
124
123
assertSame (pathMatcher , mappedInterceptor .getPathMatcher ());
125
124
}
126
125
127
126
@ Test
128
127
public void addWebRequestInterceptorsWithUrlPatterns () throws Exception {
129
- registry .addWebRequestInterceptor (webRequestInterceptor1 ).addPathPatterns ("/path1" );
130
- registry .addWebRequestInterceptor (webRequestInterceptor2 ).addPathPatterns ("/path2" );
128
+ this . registry .addWebRequestInterceptor (this . webInterceptor1 ).addPathPatterns ("/path1" );
129
+ this . registry .addWebRequestInterceptor (this . webInterceptor2 ).addPathPatterns ("/path2" );
131
130
132
131
List <HandlerInterceptor > interceptors = getInterceptorsForPath ("/path1" );
133
132
assertEquals (1 , interceptors .size ());
134
- verifyAdaptedInterceptor (interceptors .get (0 ), webRequestInterceptor1 );
133
+ verifyWebInterceptor (interceptors .get (0 ), this . webInterceptor1 );
135
134
136
135
interceptors = getInterceptorsForPath ("/path2" );
137
136
assertEquals (1 , interceptors .size ());
138
- verifyAdaptedInterceptor (interceptors .get (0 ), webRequestInterceptor2 );
137
+ verifyWebInterceptor (interceptors .get (0 ), this . webInterceptor2 );
139
138
}
140
139
141
- /**
142
- * Test for SPR-11130
143
- */
140
+ // SPR-11130
141
+
144
142
@ Test
145
143
public void addInterceptorWithExcludePathPatternOnly () {
146
- registry .addInterceptor (interceptor1 ).excludePathPatterns ("/path1/secret" );
147
- registry .addInterceptor (interceptor2 ).addPathPatterns ("/path2" );
144
+ this . registry .addInterceptor (this . interceptor1 ).excludePathPatterns ("/path1/secret" );
145
+ this . registry .addInterceptor (this . interceptor2 ).addPathPatterns ("/path2" );
148
146
149
- assertEquals (Arrays .asList (interceptor1 ), getInterceptorsForPath ("/path1" ));
150
- assertEquals (Arrays .asList (interceptor1 , interceptor2 ), getInterceptorsForPath ("/path2" ));
147
+ assertEquals (Arrays .asList (this . interceptor1 ), getInterceptorsForPath ("/path1" ));
148
+ assertEquals (Arrays .asList (this . interceptor1 , this . interceptor2 ), getInterceptorsForPath ("/path2" ));
151
149
assertEquals (Collections .emptyList (), getInterceptorsForPath ("/path1/secret" ));
152
150
}
153
151
154
152
155
153
private List <HandlerInterceptor > getInterceptorsForPath (String lookupPath ) {
156
154
PathMatcher pathMatcher = new AntPathMatcher ();
157
155
List <HandlerInterceptor > result = new ArrayList <HandlerInterceptor >();
158
- for (Object interceptor : registry .getInterceptors ()) {
156
+ for (Object interceptor : this . registry .getInterceptors ()) {
159
157
if (interceptor instanceof MappedInterceptor ) {
160
158
MappedInterceptor mappedInterceptor = (MappedInterceptor ) interceptor ;
161
159
if (mappedInterceptor .matches (lookupPath , pathMatcher )) {
@@ -172,10 +170,9 @@ else if (interceptor instanceof HandlerInterceptor) {
172
170
return result ;
173
171
}
174
172
175
- private void verifyAdaptedInterceptor (HandlerInterceptor interceptor , TestWebRequestInterceptor webInterceptor )
176
- throws Exception {
173
+ private void verifyWebInterceptor (HandlerInterceptor interceptor , TestWebRequestInterceptor webInterceptor ) throws Exception {
177
174
assertTrue (interceptor instanceof WebRequestHandlerInterceptorAdapter );
178
- interceptor .preHandle (request , response , null );
175
+ interceptor .preHandle (this . request , this . response , null );
179
176
assertTrue (webInterceptor .preHandleInvoked );
180
177
}
181
178
@@ -195,7 +192,6 @@ public void postHandle(WebRequest request, ModelMap model) throws Exception {
195
192
@ Override
196
193
public void afterCompletion (WebRequest request , Exception ex ) throws Exception {
197
194
}
198
-
199
195
}
200
196
201
197
}
0 commit comments