summaryrefslogtreecommitdiffstats
path: root/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2013-03-16 16:41:58 -0700
committerBrian Carlstrom <bdc@google.com>2013-03-16 16:42:09 -0700
commit283a5d1ff99659815a3fae78b9eab2ce856a908a (patch)
tree3c44d7aa1cf399b20c7e00c5f4910beb7a963488 /luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
parent51cf1b49bca54ec0229a51df400ad1bee580b1bb (diff)
downloadlibcore-283a5d1ff99659815a3fae78b9eab2ce856a908a.tar.gz
libcore-283a5d1ff99659815a3fae78b9eab2ce856a908a.tar.bz2
libcore-283a5d1ff99659815a3fae78b9eab2ce856a908a.zip
Fix for test_SSLSocket_HandshakeCompletedListener_RuntimeException
While this test worked fine from the dalvik command line, it failed when run as part of the frameworks test runner which overrides the default UncaughtExceptionHandler to do more than log. Bug: 8272842 Change-Id: I09d53863b901148cada8852cd46c3e88e372ac90
Diffstat (limited to 'luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java')
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java21
1 files changed, 20 insertions, 1 deletions
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
index 7ce872720..fcbb0e493 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
@@ -19,6 +19,7 @@ package libcore.javax.net.ssl;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
@@ -494,7 +495,22 @@ public class SSLSocketTest extends TestCase {
c.close();
}
+ private static final class TestUncaughtExceptionHandler implements UncaughtExceptionHandler {
+ Throwable actualException;
+ @Override public void uncaughtException(Thread thread, Throwable ex) {
+ assertNull(actualException);
+ actualException = ex;
+ }
+ }
+
public void test_SSLSocket_HandshakeCompletedListener_RuntimeException() throws Exception {
+ final Thread self = Thread.currentThread();
+ final UncaughtExceptionHandler original = self.getUncaughtExceptionHandler();
+
+ final RuntimeException expectedException = new RuntimeException("expected");
+ final TestUncaughtExceptionHandler test = new TestUncaughtExceptionHandler();
+ self.setUncaughtExceptionHandler(test);
+
final TestSSLContext c = TestSSLContext.create();
final SSLSocket client = (SSLSocket)
c.clientContext.getSocketFactory().createSocket(c.host, c.port);
@@ -509,7 +525,7 @@ public class SSLSocketTest extends TestCase {
executor.shutdown();
client.addHandshakeCompletedListener(new HandshakeCompletedListener() {
public void handshakeCompleted(HandshakeCompletedEvent event) {
- throw new RuntimeException("RuntimeException from handshakeCompleted");
+ throw expectedException;
}
});
client.startHandshake();
@@ -517,6 +533,9 @@ public class SSLSocketTest extends TestCase {
client.close();
server.close();
c.close();
+
+ assertSame(expectedException, test.actualException);
+ self.setUncaughtExceptionHandler(original);
}
public void test_SSLSocket_getUseClientMode() throws Exception {