Skip to content

Commit ad79342

Browse files
gcondraAndroid (Google) Code Review
authored andcommitted
Merge "Code cleanup for X509TrustManagerExtensionsTest.java" into jb-mr1-dev
2 parents 688ca47 + fd5a80f commit ad79342

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

core/tests/coretests/src/android/net/http/X509TrustManagerExtensionsTest.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.security.KeyStore;
2020
import java.security.cert.X509Certificate;
2121

22+
import javax.net.ssl.TrustManager;
23+
import javax.net.ssl.TrustManagerFactory;
2224
import javax.net.ssl.X509TrustManager;
2325

2426
import junit.framework.TestCase;
@@ -42,15 +44,29 @@ public void testBadCast() throws Exception {
4244
NotATrustManagerImpl ntmi = new NotATrustManagerImpl();
4345
try {
4446
X509TrustManagerExtensions tme = new X509TrustManagerExtensions(ntmi);
45-
} catch (IllegalArgumentException ignored) {
46-
return;
47+
fail();
48+
} catch (IllegalArgumentException expected) {
4749
}
48-
fail();
4950
}
5051

5152
public void testGoodCast() throws Exception {
5253
String defaultType = KeyStore.getDefaultType();
5354
TrustManagerImpl tmi = new TrustManagerImpl(KeyStore.getInstance(defaultType));
5455
X509TrustManagerExtensions tme = new X509TrustManagerExtensions(tmi);
5556
}
57+
58+
public void testNormalUseCase() throws Exception {
59+
String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
60+
TrustManagerFactory tmf = TrustManagerFactory.getInstance(defaultAlgorithm);
61+
String defaultKeystoreType = KeyStore.getDefaultType();
62+
tmf.init(KeyStore.getInstance(defaultKeystoreType));
63+
TrustManager[] tms = tmf.getTrustManagers();
64+
for (TrustManager tm : tms) {
65+
if (tm instanceof X509TrustManager) {
66+
new X509TrustManagerExtensions((X509TrustManager)tm);
67+
return;
68+
}
69+
}
70+
fail();
71+
}
5672
}

0 commit comments

Comments
 (0)