33import static org .hamcrest .Matchers .equalTo ;
44import static org .junit .Assert .assertThat ;
55
6+ import java .io .IOException ;
67import java .security .cert .X509Certificate ;
8+ import java .util .concurrent .ExecutionException ;
79import java .util .concurrent .Future ;
810
911import javax .net .ssl .SSLContext ;
@@ -44,14 +46,17 @@ public class HttpAsyncClientTest {
4446 private static final String COOKIE_DOMAIN = ".yuilibrary.com" ; // ".github.com";
4547 private static final String COOKIE_NAME = "example" ; // "JSESSIONID";
4648
49+ // tests
4750
4851 @ Test
49- public void whenUseHttpAsyncClient_thenCorrect () throws Exception {
52+ public void whenUseHttpAsyncClient_thenCorrect () throws InterruptedException , ExecutionException , IOException {
5053 final CloseableHttpAsyncClient client = HttpAsyncClients .createDefault ();
51- client .start ();
54+ // client.start();
5255 final HttpGet request = new HttpGet (HOST );
56+
5357 final Future <HttpResponse > future = client .execute (request , null );
5458 final HttpResponse response = future .get ();
59+
5560 assertThat (response .getStatusLine ().getStatusCode (), equalTo (200 ));
5661 client .close ();
5762 }
@@ -114,7 +119,6 @@ public final boolean isTrusted(final X509Certificate[] certificate, final String
114119 client .close ();
115120 }
116121
117-
118122 @ Test
119123 public void whenUseCookiesWithHttpAsyncClient_thenCorrect () throws Exception {
120124 final BasicCookieStore cookieStore = new BasicCookieStore ();
@@ -138,8 +142,8 @@ public void whenUseCookiesWithHttpAsyncClient_thenCorrect() throws Exception {
138142 @ Test
139143 public void whenUseAuthenticationWithHttpAsyncClient_thenCorrect () throws Exception {
140144 final CredentialsProvider provider = new BasicCredentialsProvider ();
141- final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials (DEFAULT_USER , DEFAULT_PASS );
142- provider .setCredentials (AuthScope .ANY , credentials );
145+ final UsernamePasswordCredentials creds = new UsernamePasswordCredentials (DEFAULT_USER , DEFAULT_PASS );
146+ provider .setCredentials (AuthScope .ANY , creds );
143147 final CloseableHttpAsyncClient client = HttpAsyncClients .custom ().setDefaultCredentialsProvider (provider ).build ();
144148
145149 final HttpGet request = new HttpGet (URL_SECURED_BY_BASIC_AUTHENTICATION );
@@ -175,4 +179,3 @@ public void run() {
175179
176180 }
177181}
178-
0 commit comments