14
14
*/
15
15
16
16
import static org .asynchttpclient .Dsl .get ;
17
+ import static org .mockito .Matchers .anyObject ;
17
18
import static org .mockito .Mockito .*;
18
19
import static org .powermock .api .mockito .PowerMockito .mock ;
19
20
import static org .testng .Assert .*;
21
+ import io .netty .handler .codec .http .DefaultHttpHeaders ;
22
+ import io .netty .handler .codec .http .HttpHeaders ;
20
23
21
24
import java .io .IOException ;
22
25
import java .nio .ByteBuffer ;
23
26
24
27
import org .asynchttpclient .AsyncHandler ;
25
28
import org .asynchttpclient .AsyncHandler .State ;
26
- import org .asynchttpclient .netty .NettyResponseHeaders ;
27
29
import org .asynchttpclient .HttpResponseBodyPart ;
28
30
import org .asynchttpclient .HttpResponseHeaders ;
29
31
import org .asynchttpclient .HttpResponseStatus ;
30
32
import org .asynchttpclient .Request ;
33
+ import org .asynchttpclient .Response ;
31
34
import org .asynchttpclient .uri .Uri ;
32
35
import org .powermock .api .mockito .PowerMockito ;
33
36
import org .powermock .core .classloader .annotations .PrepareForTest ;
34
37
import org .powermock .modules .testng .PowerMockTestCase ;
35
38
import org .testng .annotations .Test ;
36
39
37
- import io .netty .handler .codec .http .DefaultHttpHeaders ;
38
- import io .netty .handler .codec .http .HttpHeaders ;
39
-
40
40
/**
41
41
* @author Benjamin Hanzelmann
42
42
*/
@@ -88,7 +88,8 @@ public void testOnStatusReceivedOkStatusWithDecoratedAsyncHandler() throws Excep
88
88
when (mockResponseStatus .getStatusCode ()).thenReturn (200 );
89
89
when (mockResponseStatus .getUri ()).thenReturn (mock (Uri .class ));
90
90
91
- AsyncHandler decoratedAsyncHandler = mock (AsyncHandler .class );
91
+ @ SuppressWarnings ("unchecked" )
92
+ AsyncHandler <Response > decoratedAsyncHandler = mock (AsyncHandler .class );
92
93
State mockState = mock (State .class );
93
94
when (decoratedAsyncHandler .onStatusReceived (mockResponseStatus )).thenReturn (mockState );
94
95
@@ -142,7 +143,8 @@ public void testOnBodyPartReceivedWithDecoratedAsyncHandler() throws Exception {
142
143
ByteBuffer buffer = ByteBuffer .allocate (0 );
143
144
when (bodyPart .getBodyByteBuffer ()).thenReturn (buffer );
144
145
145
- AsyncHandler decoratedAsyncHandler = mock (AsyncHandler .class );
146
+ @ SuppressWarnings ("unchecked" )
147
+ AsyncHandler <Response > decoratedAsyncHandler = mock (AsyncHandler .class );
146
148
State mockState = mock (State .class );
147
149
when (decoratedAsyncHandler .onBodyPartReceived (bodyPart )).thenReturn (mockState );
148
150
@@ -165,17 +167,18 @@ public void testOnBodyPartReceivedWithDecoratedAsyncHandler() throws Exception {
165
167
public void testOnHeadersReceived () throws Exception {
166
168
ResumableAsyncHandler handler = new ResumableAsyncHandler ();
167
169
HttpHeaders responseHeaders = new DefaultHttpHeaders ();
168
- HttpResponseHeaders headers = new NettyResponseHeaders (responseHeaders );
170
+ HttpResponseHeaders headers = new HttpResponseHeaders (responseHeaders );
169
171
State status = handler .onHeadersReceived (headers );
170
172
assertEquals (status , AsyncHandler .State .CONTINUE , "State should be CONTINUE for a successful onHeadersReceived" );
171
173
}
172
174
173
175
@ Test
174
176
public void testOnHeadersReceivedWithDecoratedAsyncHandler () throws Exception {
175
177
HttpHeaders responseHeaders = new DefaultHttpHeaders ();
176
- HttpResponseHeaders headers = new NettyResponseHeaders (responseHeaders );
178
+ HttpResponseHeaders headers = new HttpResponseHeaders (responseHeaders );
177
179
178
- AsyncHandler decoratedAsyncHandler = mock (AsyncHandler .class );
180
+ @ SuppressWarnings ("unchecked" )
181
+ AsyncHandler <Response > decoratedAsyncHandler = mock (AsyncHandler .class );
179
182
State mockState = mock (State .class );
180
183
when (decoratedAsyncHandler .onHeadersReceived (headers )).thenReturn (mockState );
181
184
@@ -189,7 +192,7 @@ public void testOnHeadersReceivedContentLengthMinus() throws Exception {
189
192
ResumableAsyncHandler handler = new ResumableAsyncHandler ();
190
193
HttpHeaders responseHeaders = new DefaultHttpHeaders ();
191
194
responseHeaders .add (HttpHeaders .Names .CONTENT_LENGTH , -1 );
192
- HttpResponseHeaders headers = new NettyResponseHeaders (responseHeaders );
195
+ HttpResponseHeaders headers = new HttpResponseHeaders (responseHeaders );
193
196
State status = handler .onHeadersReceived (headers );
194
197
assertEquals (status , AsyncHandler .State .ABORT , "State should be ABORT for content length -1" );
195
198
}
0 commit comments