1717
1818import nl .altindag .client .model .ClientResponse ;
1919import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
20- import org .apache .hc .client5 .http .impl .classic .CloseableHttpResponse ;
2120import org .apache .hc .core5 .http .ClassicHttpRequest ;
22- import org .apache .hc .core5 .http .HttpEntity ;
21+ import org .apache .hc .core5 .http .io . HttpClientResponseHandler ;
2322import org .junit .jupiter .api .Test ;
2423import org .junit .jupiter .api .extension .ExtendWith ;
2524import org .mockito .ArgumentCaptor ;
2625import org .mockito .InjectMocks ;
2726import org .mockito .Mock ;
2827import org .mockito .junit .jupiter .MockitoExtension ;
2928
30- import java .io .ByteArrayInputStream ;
31- import java .io .InputStream ;
32-
3329import static nl .altindag .client .ClientType .APACHE5_HTTP_CLIENT ;
3430import static nl .altindag .client .Constants .HEADER_KEY_CLIENT_TYPE ;
3531import static nl .altindag .client .TestConstants .GET_METHOD ;
3632import static nl .altindag .client .TestConstants .HTTP_URL ;
3733import static org .assertj .core .api .Assertions .assertThat ;
3834import static org .mockito .ArgumentMatchers .any ;
39- import static org .mockito .Mockito .mock ;
4035import static org .mockito .Mockito .times ;
4136import static org .mockito .Mockito .verify ;
4237import static org .mockito .Mockito .when ;
@@ -51,25 +46,16 @@ class Apache5HttpClientServiceShould {
5146
5247 @ Test
5348 void executeRequest () throws Exception {
54- CloseableHttpResponse response = mock (CloseableHttpResponse .class );
55- HttpEntity entity = mock (HttpEntity .class );
56- InputStream stream = new ByteArrayInputStream ("Hello" .getBytes ());
57-
58- when (entity .getContent ()).thenReturn (stream );
59- when (response .getEntity ()).thenReturn (entity );
60- when (response .getCode ()).thenReturn (200 );
61-
62- when (httpClient .execute (any (ClassicHttpRequest .class ))).thenReturn (response );
49+ ClientResponse mockClientResponse = new ClientResponse ("Hello" , 200 );
50+ when (httpClient .execute (any (ClassicHttpRequest .class ), any (HttpClientResponseHandler .class ))).thenReturn (mockClientResponse );
6351
6452 ArgumentCaptor <ClassicHttpRequest > requestArgumentCaptor = ArgumentCaptor .forClass (ClassicHttpRequest .class );
6553 ClientResponse clientResponse = victim .executeRequest (HTTP_URL );
6654
67- stream .close ();
68-
6955 assertThat (clientResponse .getStatusCode ()).isEqualTo (200 );
7056 assertThat (clientResponse .getResponseBody ()).isEqualTo ("Hello" );
7157
72- verify (httpClient , times (1 )).execute (requestArgumentCaptor .capture ());
58+ verify (httpClient , times (1 )).execute (requestArgumentCaptor .capture (), any ( HttpClientResponseHandler . class ) );
7359 assertThat (requestArgumentCaptor .getValue ().getUri ()).hasToString (HTTP_URL );
7460 assertThat (requestArgumentCaptor .getValue ().getMethod ()).isEqualTo (GET_METHOD );
7561 assertThat (requestArgumentCaptor .getValue ().getHeaders ()).hasSize (1 );
0 commit comments