1919import java .security .KeyStore ;
2020import java .security .cert .X509Certificate ;
2121
22+ import javax .net .ssl .TrustManager ;
23+ import javax .net .ssl .TrustManagerFactory ;
2224import javax .net .ssl .X509TrustManager ;
2325
2426import 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