2323import java .util .HashMap ;
2424
2525import static com .github .greengerong .PrerenderSeoService .ESCAPED_FRAGMENT_KEY ;
26+ import static org .apache .http .HttpStatus .SC_NOT_FOUND ;
2627import static org .apache .http .HttpStatus .SC_OK ;
28+ import static org .apache .http .client .methods .HttpGet .METHOD_NAME ;
2729import static org .mockito .Mockito .*;
2830
2931@ RunWith (MockitoJUnitRunner .class )
3032public class PreRenderSEOFilterTest {
3133
32- public static final int NOT_FOUND = 404 ;
3334 private PreRenderSEOFilter preRenderSEOFilter ;
3435
3536 @ Mock
@@ -95,7 +96,7 @@ public void should_handle_when_url_with_escaped_fragment_() throws Exception {
9596 final StatusLine statusLine = mock (StatusLine .class );
9697
9798 when (servletRequest .getRequestURL ()).thenReturn (new StringBuffer ("http://localhost/test" ));
98- when (servletRequest .getMethod ()).thenReturn (HttpGet . METHOD_NAME );
99+ when (servletRequest .getMethod ()).thenReturn (METHOD_NAME );
99100 when (servletRequest .getHeaderNames ()).thenReturn (mock (Enumeration .class ));
100101 when (httpClient .execute (httpGet )).thenReturn (httpResponse );
101102 when (httpResponse .getStatusLine ()).thenReturn (statusLine );
@@ -120,7 +121,7 @@ public void should_not_handle_when_user_agent_is_not_crawler() throws Exception
120121 preRenderSEOFilter .init (filterConfig );
121122
122123 when (servletRequest .getRequestURL ()).thenReturn (new StringBuffer ("http://localhost/test" ));
123- when (servletRequest .getMethod ()).thenReturn (HttpGet . METHOD_NAME );
124+ when (servletRequest .getMethod ()).thenReturn (METHOD_NAME );
124125 when (servletRequest .getParameterMap ()).thenReturn (Maps .<String , String >newHashMap ());
125126 when (servletRequest .getHeader ("User-Agent" )).thenReturn ("no" );
126127 //when
@@ -138,7 +139,7 @@ public void should_not_handle_when_url_is_a_resource() throws Exception {
138139 preRenderSEOFilter .init (filterConfig );
139140
140141 when (servletRequest .getRequestURL ()).thenReturn (new StringBuffer ("http://localhost/test.js" ));
141- when (servletRequest .getMethod ()).thenReturn (HttpGet . METHOD_NAME );
142+ when (servletRequest .getMethod ()).thenReturn (METHOD_NAME );
142143 when (servletRequest .getParameterMap ()).thenReturn (Maps .<String , String >newHashMap ());
143144 when (servletRequest .getHeader ("User-Agent" )).thenReturn ("crawler1" );
144145 //when
@@ -157,7 +158,7 @@ public void should_not_handle_when_white_list_is_not_empty_and_url_is_not_in_whi
157158 preRenderSEOFilter .init (filterConfig );
158159
159160 when (servletRequest .getRequestURL ()).thenReturn (new StringBuffer ("http://localhost/test" ));
160- when (servletRequest .getMethod ()).thenReturn (HttpGet . METHOD_NAME );
161+ when (servletRequest .getMethod ()).thenReturn (METHOD_NAME );
161162 when (servletRequest .getParameterMap ()).thenReturn (Maps .<String , String >newHashMap ());
162163 when (servletRequest .getHeader ("User-Agent" )).thenReturn ("crawler1" );
163164 //when
@@ -176,7 +177,7 @@ public void should_not_handle_when_black_list_is_not_empty_and_url_is_in_black_l
176177 preRenderSEOFilter .init (filterConfig );
177178
178179 when (servletRequest .getRequestURL ()).thenReturn (new StringBuffer ("http://localhost/test" ));
179- when (servletRequest .getMethod ()).thenReturn (HttpGet . METHOD_NAME );
180+ when (servletRequest .getMethod ()).thenReturn (METHOD_NAME );
180181 when (servletRequest .getParameterMap ()).thenReturn (Maps .<String , String >newHashMap ());
181182 when (servletRequest .getHeader ("User-Agent" )).thenReturn ("crawler1" );
182183 //when
@@ -197,7 +198,7 @@ public void should_handle_when_user_agent_is_crawler_and_url_is_not_resource_and
197198 final StatusLine statusLine = mock (StatusLine .class );
198199
199200 when (servletRequest .getRequestURL ()).thenReturn (new StringBuffer ("http://localhost/test" ));
200- when (servletRequest .getMethod ()).thenReturn (HttpGet . METHOD_NAME );
201+ when (servletRequest .getMethod ()).thenReturn (METHOD_NAME );
201202 when (servletRequest .getHeader ("User-Agent" )).thenReturn ("crawler1" );
202203
203204 when (servletRequest .getHeaderNames ()).thenReturn (mock (Enumeration .class ));
@@ -227,7 +228,7 @@ public void should_handle_when_every_thing_is_ok_but_prerender_server_response_i
227228 final StatusLine statusLine = mock (StatusLine .class );
228229
229230 when (servletRequest .getRequestURL ()).thenReturn (new StringBuffer ("http://localhost/test" ));
230- when (servletRequest .getMethod ()).thenReturn (HttpGet . METHOD_NAME );
231+ when (servletRequest .getMethod ()).thenReturn (METHOD_NAME );
231232 when (servletRequest .getHeader ("User-Agent" )).thenReturn ("crawler1" );
232233
233234 when (servletRequest .getHeaderNames ()).thenReturn (mock (Enumeration .class ));
@@ -236,7 +237,7 @@ public void should_handle_when_every_thing_is_ok_but_prerender_server_response_i
236237 final HashMap <String , String > map = Maps .newHashMap ();
237238 map .put (ESCAPED_FRAGMENT_KEY , "" );
238239 when (servletRequest .getParameterMap ()).thenReturn (map );
239- when (statusLine .getStatusCode ()).thenReturn (NOT_FOUND );
240+ when (statusLine .getStatusCode ()).thenReturn (SC_NOT_FOUND );
240241 when (httpResponse .getAllHeaders ()).thenReturn (new Header [0 ]);
241242 when (servletResponse .getWriter ()).thenReturn (printWriter );
242243
@@ -247,7 +248,7 @@ public void should_handle_when_every_thing_is_ok_but_prerender_server_response_i
247248 //then
248249 verify (httpClient ).execute (httpGet );
249250 verify (filterChain , never ()).doFilter (servletRequest , servletResponse );
250- verify (servletResponse ).setStatus (NOT_FOUND );
251+ verify (servletResponse ).setStatus (SC_NOT_FOUND );
251252 }
252253
253254
@@ -264,7 +265,7 @@ public void should_handle_when_user_agent_is_crawler_and_url_is_not_resource_and
264265 final StatusLine statusLine = mock (StatusLine .class );
265266
266267 when (servletRequest .getRequestURL ()).thenReturn (new StringBuffer ("http://localhost/test" ));
267- when (servletRequest .getMethod ()).thenReturn (HttpGet . METHOD_NAME );
268+ when (servletRequest .getMethod ()).thenReturn (METHOD_NAME );
268269 when (servletRequest .getHeader ("User-Agent" )).thenReturn ("crawler1" );
269270
270271 when (servletRequest .getHeaderNames ()).thenReturn (mock (Enumeration .class ));
@@ -298,7 +299,7 @@ public void should_use_request_url_from_custom_header_if_available() throws Exce
298299 final StatusLine statusLine = mock (StatusLine .class );
299300
300301 when (servletRequest .getRequestURL ()).thenReturn (new StringBuffer ("http://localhost/test" ));
301- when (servletRequest .getMethod ()).thenReturn (HttpGet . METHOD_NAME );
302+ when (servletRequest .getMethod ()).thenReturn (METHOD_NAME );
302303 when (servletRequest .getHeader ("X-Forwarded-URL" )).thenReturn ("http://my.public.domain.com/" );
303304
304305 when (servletRequest .getHeaderNames ()).thenReturn (mock (Enumeration .class ));
0 commit comments