17
17
import org .asynchttpclient .*;
18
18
import org .asynchttpclient .AsyncHandler .State ;
19
19
import org .asynchttpclient .uri .Uri ;
20
- import org .powermock .api .mockito .PowerMockito ;
21
- import org .powermock .core .classloader .annotations .PrepareForTest ;
22
- import org .powermock .modules .testng .PowerMockTestCase ;
23
20
import org .testng .annotations .Test ;
24
21
25
22
import java .io .IOException ;
28
25
import static io .netty .handler .codec .http .HttpHeaderNames .CONTENT_LENGTH ;
29
26
import static io .netty .handler .codec .http .HttpHeaderNames .RANGE ;
30
27
import static org .asynchttpclient .Dsl .get ;
31
- import static org .mockito .Matchers .anyObject ;
32
- import static org .mockito .Mockito .doThrow ;
33
- import static org .mockito .Mockito .verify ;
34
- import static org .mockito .Mockito .when ;
35
- import static org .powermock .api .mockito .PowerMockito .mock ;
28
+ import static org .mockito .Mockito .*;
36
29
import static org .testng .Assert .assertEquals ;
37
30
import static org .testng .Assert .assertNull ;
38
31
39
32
/**
40
33
* @author Benjamin Hanzelmann
41
34
*/
42
- @ PrepareForTest ({HttpResponseStatus .class , State .class })
43
- public class ResumableAsyncHandlerTest extends PowerMockTestCase {
35
+ public class ResumableAsyncHandlerTest {
44
36
@ Test
45
37
public void testAdjustRange () {
46
38
MapResumableProcessor proc = new MapResumableProcessor ();
@@ -89,14 +81,13 @@ public void testOnStatusReceivedOkStatusWithDecoratedAsyncHandler() throws Excep
89
81
90
82
@ SuppressWarnings ("unchecked" )
91
83
AsyncHandler <Response > decoratedAsyncHandler = mock (AsyncHandler .class );
92
- State mockState = mock (State .class );
93
- when (decoratedAsyncHandler .onStatusReceived (mockResponseStatus )).thenReturn (mockState );
84
+ when (decoratedAsyncHandler .onStatusReceived (mockResponseStatus )).thenReturn (State .CONTINUE );
94
85
95
86
ResumableAsyncHandler handler = new ResumableAsyncHandler (decoratedAsyncHandler );
96
87
97
88
State state = handler .onStatusReceived (mockResponseStatus );
98
89
verify (decoratedAsyncHandler ).onStatusReceived (mockResponseStatus );
99
- assertEquals (state , mockState , "State returned should be equal to the one returned from decoratedAsyncHandler" );
90
+ assertEquals (state , State . CONTINUE , "State returned should be equal to the one returned from decoratedAsyncHandler" );
100
91
}
101
92
102
93
@ Test
@@ -113,7 +104,7 @@ public void testOnStatusReceived500Status() throws Exception {
113
104
@ Test
114
105
public void testOnBodyPartReceived () throws Exception {
115
106
ResumableAsyncHandler handler = new ResumableAsyncHandler ();
116
- HttpResponseBodyPart bodyPart = PowerMockito . mock (HttpResponseBodyPart .class );
107
+ HttpResponseBodyPart bodyPart = mock (HttpResponseBodyPart .class );
117
108
when (bodyPart .getBodyPartBytes ()).thenReturn (new byte [0 ]);
118
109
ByteBuffer buffer = ByteBuffer .allocate (0 );
119
110
when (bodyPart .getBodyByteBuffer ()).thenReturn (buffer );
@@ -125,40 +116,38 @@ public void testOnBodyPartReceived() throws Exception {
125
116
public void testOnBodyPartReceivedWithResumableListenerThrowsException () throws Exception {
126
117
ResumableAsyncHandler handler = new ResumableAsyncHandler ();
127
118
128
- ResumableListener resumableListener = PowerMockito . mock (ResumableListener .class );
129
- doThrow (new IOException ()).when (resumableListener ).onBytesReceived (anyObject ());
119
+ ResumableListener resumableListener = mock (ResumableListener .class );
120
+ doThrow (new IOException ()).when (resumableListener ).onBytesReceived (any ());
130
121
handler .setResumableListener (resumableListener );
131
122
132
- HttpResponseBodyPart bodyPart = PowerMockito . mock (HttpResponseBodyPart .class );
123
+ HttpResponseBodyPart bodyPart = mock (HttpResponseBodyPart .class );
133
124
State state = handler .onBodyPartReceived (bodyPart );
134
125
assertEquals (state , AsyncHandler .State .ABORT ,
135
126
"State should be ABORT if the resumableListener threw an exception in onBodyPartReceived" );
136
127
}
137
128
138
129
@ Test
139
130
public void testOnBodyPartReceivedWithDecoratedAsyncHandler () throws Exception {
140
- HttpResponseBodyPart bodyPart = PowerMockito . mock (HttpResponseBodyPart .class );
131
+ HttpResponseBodyPart bodyPart = mock (HttpResponseBodyPart .class );
141
132
when (bodyPart .getBodyPartBytes ()).thenReturn (new byte [0 ]);
142
133
ByteBuffer buffer = ByteBuffer .allocate (0 );
143
134
when (bodyPart .getBodyByteBuffer ()).thenReturn (buffer );
144
135
145
136
@ SuppressWarnings ("unchecked" )
146
137
AsyncHandler <Response > decoratedAsyncHandler = mock (AsyncHandler .class );
147
- State mockState = mock (State .class );
148
- when (decoratedAsyncHandler .onBodyPartReceived (bodyPart )).thenReturn (mockState );
138
+ when (decoratedAsyncHandler .onBodyPartReceived (bodyPart )).thenReturn (State .CONTINUE );
149
139
150
140
// following is needed to set the url variable
151
141
HttpResponseStatus mockResponseStatus = mock (HttpResponseStatus .class );
152
142
when (mockResponseStatus .getStatusCode ()).thenReturn (200 );
153
- Uri mockUri = mock (Uri .class );
154
- when (mockUri .toUrl ()).thenReturn ("http://non.null" );
155
- when (mockResponseStatus .getUri ()).thenReturn (mockUri );
143
+ Uri uri = Uri .create ("http://non.null" );
144
+ when (mockResponseStatus .getUri ()).thenReturn (uri );
156
145
157
146
ResumableAsyncHandler handler = new ResumableAsyncHandler (decoratedAsyncHandler );
158
147
handler .onStatusReceived (mockResponseStatus );
159
148
160
149
State state = handler .onBodyPartReceived (bodyPart );
161
- assertEquals (state , mockState , "State should be equal to the state returned from decoratedAsyncHandler" );
150
+ assertEquals (state , State . CONTINUE , "State should be equal to the state returned from decoratedAsyncHandler" );
162
151
163
152
}
164
153
@@ -176,12 +165,11 @@ public void testOnHeadersReceivedWithDecoratedAsyncHandler() throws Exception {
176
165
177
166
@ SuppressWarnings ("unchecked" )
178
167
AsyncHandler <Response > decoratedAsyncHandler = mock (AsyncHandler .class );
179
- State mockState = mock (State .class );
180
- when (decoratedAsyncHandler .onHeadersReceived (responseHeaders )).thenReturn (mockState );
168
+ when (decoratedAsyncHandler .onHeadersReceived (responseHeaders )).thenReturn (State .CONTINUE );
181
169
182
170
ResumableAsyncHandler handler = new ResumableAsyncHandler (decoratedAsyncHandler );
183
171
State status = handler .onHeadersReceived (responseHeaders );
184
- assertEquals (status , mockState , "State should be equal to the state returned from decoratedAsyncHandler" );
172
+ assertEquals (status , State . CONTINUE , "State should be equal to the state returned from decoratedAsyncHandler" );
185
173
}
186
174
187
175
@ Test
0 commit comments