Skip to content

Commit 29cbf11

Browse files
committed
Fix tests
1 parent 0ed8d90 commit 29cbf11

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/test/java/com/ning/http/client/async/AsyncProvidersBasicTest.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
import static java.nio.charset.StandardCharsets.*;
1919
import static com.ning.http.util.DateUtils.millisTime;
2020
import static com.ning.http.util.MiscUtils.isNonEmpty;
21-
import static org.testng.Assert.assertEquals;
22-
import static org.testng.Assert.assertNull;
23-
import static org.testng.Assert.assertTrue;
24-
import static org.testng.Assert.fail;
21+
import static org.testng.Assert.*;
2522

2623
import org.testng.Assert;
2724
import org.testng.annotations.Test;
@@ -47,6 +44,7 @@
4744
import java.net.ConnectException;
4845
import java.net.HttpURLConnection;
4946
import java.net.URL;
47+
import java.net.UnknownHostException;
5048
import java.nio.channels.UnresolvedAddressException;
5149
import java.util.Arrays;
5250
import java.util.HashMap;
@@ -996,27 +994,27 @@ public void onThrowable(Throwable t) {
996994
}
997995
}
998996

999-
@Test(groups = { "online", "default_provider", "async" })
997+
@Test(groups = { "online", "default_provider", "async" }, expectedExceptions = { ConnectException.class, UnresolvedAddressException.class, UnknownHostException.class })
1000998
public void asyncConnectInvalidHandlerHost() throws Throwable {
1001999
try (AsyncHttpClient client = getAsyncHttpClient(null)) {
1000+
1001+
final AtomicReference<Throwable> e = new AtomicReference<>();
10021002
final CountDownLatch l = new CountDownLatch(1);
10031003

10041004
client.prepareGet("http://null.apache.org:9999/").execute(new AsyncCompletionHandlerAdapter() {
10051005
@Override
10061006
public void onThrowable(Throwable t) {
1007-
if (t != null) {
1008-
if (t.getClass().equals(ConnectException.class)) {
1009-
l.countDown();
1010-
} else if (t.getClass().equals(UnresolvedAddressException.class)) {
1011-
l.countDown();
1012-
}
1013-
}
1007+
e.set(t);
1008+
l.countDown();
10141009
}
10151010
});
10161011

10171012
if (!l.await(TIMEOUT, TimeUnit.SECONDS)) {
10181013
Assert.fail("Timed out");
10191014
}
1015+
1016+
assertNotNull(e.get());
1017+
throw e.get();
10201018
}
10211019
}
10221020

src/test/java/com/ning/http/client/ws/CloseCodeReasonMessageTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ public void onError(Throwable t) {
117117

118118
latch.await();
119119
}
120-
121-
@Test(timeOut = 60000)
120+
121+
// Netty would throw IllegalArgumentException, other providers IllegalStateException
122+
@Test(timeOut = 60000, expectedExceptions = { IllegalStateException.class, IllegalArgumentException.class } )
122123
public void wrongStatusCode() throws Throwable {
123124
try (AsyncHttpClient client = getAsyncHttpClient(null)) {
124125
final CountDownLatch latch = new CountDownLatch(1);
@@ -147,11 +148,12 @@ public void onError(Throwable t) {
147148

148149
latch.await();
149150
assertNotNull(throwable.get());
150-
assertEquals(throwable.get().getClass(), IllegalStateException.class);
151+
throw throwable.get();
151152
}
152153
}
153154

154-
@Test(timeOut = 60000)
155+
// Netty would throw IllegalArgumentException, other providers IllegalStateException
156+
@Test(timeOut = 60000, expectedExceptions = { IllegalStateException.class, IllegalArgumentException.class } )
155157
public void wrongProtocolCode() throws Throwable {
156158
try (AsyncHttpClient client = getAsyncHttpClient(null)) {
157159
final CountDownLatch latch = new CountDownLatch(1);
@@ -180,7 +182,7 @@ public void onError(Throwable t) {
180182

181183
latch.await();
182184
assertNotNull(throwable.get());
183-
assertEquals(throwable.get().getClass(), IllegalStateException.class);
185+
throw throwable.get();
184186
}
185187
}
186188
}

src/test/java/com/ning/http/client/ws/TextMessageTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.IOException;
2626
import java.net.ConnectException;
27+
import java.net.UnknownHostException;
2728
import java.nio.channels.UnresolvedAddressException;
2829
import java.util.concurrent.CountDownLatch;
2930
import java.util.concurrent.ExecutionException;
@@ -116,7 +117,7 @@ public void onEmptyListenerTest() throws Throwable {
116117
}
117118
}
118119

119-
@Test(timeOut = 60000, expectedExceptions = { ConnectException.class, UnresolvedAddressException.class })
120+
@Test(timeOut = 60000, expectedExceptions = { ConnectException.class, UnresolvedAddressException.class, UnknownHostException.class })
120121
public void onFailureTest() throws Throwable {
121122
try (AsyncHttpClient c = getAsyncHttpClient(null)) {
122123
c.prepareGet("ws://abcdefg").execute(new WebSocketUpgradeHandler.Builder().build()).get();

0 commit comments

Comments
 (0)