3434import static org .asynchttpclient .Dsl .basicAuthRealm ;
3535import static org .asynchttpclient .test .TestUtils .*;
3636import static org .testng .Assert .assertEquals ;
37- import static org .testng .Assert .assertTrue ;
37+ import static org .testng .Assert .assertNotNull ;
3838
3939public class MultipartBasicAuthTest extends AbstractBasicTest {
4040
@@ -54,33 +54,35 @@ public AbstractHandler configureHandler() throws Exception {
5454 return new BasicAuthTest .SimpleHandler ();
5555 }
5656
57- private void expectBrokenPipe (Function <BoundRequestBuilder , BoundRequestBuilder > f ) throws Exception {
57+ private void expectExecutionException (Function <BoundRequestBuilder , BoundRequestBuilder > f ) throws Throwable {
5858 File file = createTempFile (1024 * 1024 );
5959
60- Throwable cause = null ;
60+ ExecutionException executionException = null ;
6161 try (AsyncHttpClient client = asyncHttpClient ()) {
6262 try {
6363 for (int i = 0 ; i < 20 ; i ++) {
6464 f .apply (client .preparePut (getTargetUrl ())
6565 .addBodyPart (new FilePart ("test" , file , APPLICATION_OCTET_STREAM .toString (), UTF_8 )))
66- .execute ().get ();
66+ .execute ()
67+ .get ();
6768 }
6869 } catch (ExecutionException e ) {
69- cause = e . getCause () ;
70+ executionException = e ;
7071 }
7172 }
7273
73- assertTrue (cause instanceof IOException , "Expected an IOException" );
74+ assertNotNull (executionException , "Expected ExecutionException" );
75+ throw executionException .getCause ();
7476 }
7577
76- @ Test
77- public void noRealmCausesServerToCloseSocket () throws Exception {
78- expectBrokenPipe (rb -> rb );
78+ @ Test ( expectedExceptions = IOException . class )
79+ public void noRealmCausesServerToCloseSocket () throws Throwable {
80+ expectExecutionException (rb -> rb );
7981 }
8082
81- @ Test
82- public void unauthorizedNonPreemptiveRealmCausesServerToCloseSocket () throws Exception {
83- expectBrokenPipe (rb -> rb .setRealm (basicAuthRealm (USER , ADMIN )));
83+ @ Test ( expectedExceptions = IOException . class )
84+ public void unauthorizedNonPreemptiveRealmCausesServerToCloseSocket () throws Throwable {
85+ expectExecutionException (rb -> rb .setRealm (basicAuthRealm (USER , ADMIN )));
8486 }
8587
8688 private void expectSuccess (Function <BoundRequestBuilder , BoundRequestBuilder > f ) throws Exception {
0 commit comments