1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2015 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.
26
26
import org .springframework .mock .web .test .MockHttpServletRequest ;
27
27
import org .springframework .mock .web .test .MockHttpServletResponse ;
28
28
29
- import static org .hamcrest .Matchers .*;
30
- import static org .junit .Assert .*;
31
- import static org .mockito .BDDMockito .*;
29
+ import static org .hamcrest .Matchers .containsString ;
30
+ import static org .junit .Assert .assertEquals ;
31
+ import static org .junit .Assert .assertFalse ;
32
+ import static org .junit .Assert .assertNotNull ;
33
+ import static org .junit .Assert .assertSame ;
34
+ import static org .junit .Assert .assertThat ;
35
+ import static org .junit .Assert .assertTrue ;
36
+ import static org .junit .Assert .fail ;
37
+ import static org .mockito .BDDMockito .mock ;
38
+ import static org .mockito .BDDMockito .verify ;
32
39
33
40
/**
34
41
* A test fixture with a {@link StandardServletAsyncWebRequest}.
35
- *
36
42
* @author Rossen Stoyanchev
37
43
*/
38
44
public class StandardServletAsyncWebRequestTests {
@@ -43,6 +49,7 @@ public class StandardServletAsyncWebRequestTests {
43
49
44
50
private MockHttpServletResponse response ;
45
51
52
+
46
53
@ Before
47
54
public void setup () {
48
55
this .request = new MockHttpServletRequest ();
@@ -52,10 +59,10 @@ public void setup() {
52
59
this .asyncRequest .setTimeout (44 *1000L );
53
60
}
54
61
62
+
55
63
@ Test
56
64
public void isAsyncStarted () throws Exception {
57
65
assertFalse (this .asyncRequest .isAsyncStarted ());
58
-
59
66
this .asyncRequest .startAsync ();
60
67
assertTrue (this .asyncRequest .isAsyncStarted ());
61
68
}
@@ -64,12 +71,11 @@ public void isAsyncStarted() throws Exception {
64
71
public void startAsync () throws Exception {
65
72
this .asyncRequest .startAsync ();
66
73
67
- MockAsyncContext asyncContext = (MockAsyncContext ) this .request .getAsyncContext ();
68
-
69
- assertNotNull (asyncContext );
70
- assertEquals ("Timeout value not set" , 44 * 1000 , asyncContext .getTimeout ());
71
- assertEquals (1 , asyncContext .getListeners ().size ());
72
- assertSame (this .asyncRequest , asyncContext .getListeners ().get (0 ));
74
+ MockAsyncContext context = (MockAsyncContext ) this .request .getAsyncContext ();
75
+ assertNotNull (context );
76
+ assertEquals ("Timeout value not set" , 44 * 1000 , context .getTimeout ());
77
+ assertEquals (1 , context .getListeners ().size ());
78
+ assertSame (this .asyncRequest , context .getListeners ().get (0 ));
73
79
}
74
80
75
81
@ Test
@@ -79,10 +85,9 @@ public void startAsyncMultipleTimes() throws Exception {
79
85
this .asyncRequest .startAsync ();
80
86
this .asyncRequest .startAsync (); // idempotent
81
87
82
- MockAsyncContext asyncContext = (MockAsyncContext ) this .request .getAsyncContext ();
83
-
84
- assertNotNull (asyncContext );
85
- assertEquals (1 , asyncContext .getListeners ().size ());
88
+ MockAsyncContext context = (MockAsyncContext ) this .request .getAsyncContext ();
89
+ assertNotNull (context );
90
+ assertEquals (1 , context .getListeners ().size ());
86
91
}
87
92
88
93
@ Test
@@ -118,10 +123,8 @@ public void onTimeoutDefaultBehavior() throws Exception {
118
123
@ Test
119
124
public void onTimeoutTimeoutHandler () throws Exception {
120
125
Runnable timeoutHandler = mock (Runnable .class );
121
-
122
126
this .asyncRequest .addTimeoutHandler (timeoutHandler );
123
127
this .asyncRequest .onTimeout (new AsyncEvent (null ));
124
-
125
128
verify (timeoutHandler ).run ();
126
129
}
127
130
0 commit comments