Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad793427 authored by Geremy Condra's avatar Geremy Condra Committed by Android (Google) Code Review
Browse files

Merge "Code cleanup for X509TrustManagerExtensionsTest.java" into jb-mr1-dev

parents 688ca470 fd5a80f6
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.net.http;
import java.security.KeyStore;
import java.security.cert.X509Certificate;

import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;

import junit.framework.TestCase;
@@ -42,10 +44,9 @@ public class X509TrustManagerExtensionsTest extends TestCase {
        NotATrustManagerImpl ntmi = new NotATrustManagerImpl();
        try {
            X509TrustManagerExtensions tme = new X509TrustManagerExtensions(ntmi);
        } catch (IllegalArgumentException ignored) {
            return;
        }
            fail();
        } catch (IllegalArgumentException expected) {
        }
    }

    public void testGoodCast() throws Exception {
@@ -53,4 +54,19 @@ public class X509TrustManagerExtensionsTest extends TestCase {
        TrustManagerImpl tmi = new TrustManagerImpl(KeyStore.getInstance(defaultType));
        X509TrustManagerExtensions tme = new X509TrustManagerExtensions(tmi);
    }

    public void testNormalUseCase() throws Exception {
        String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(defaultAlgorithm);
        String defaultKeystoreType = KeyStore.getDefaultType();
        tmf.init(KeyStore.getInstance(defaultKeystoreType));
        TrustManager[] tms = tmf.getTrustManagers();
        for (TrustManager tm : tms) {
            if (tm instanceof X509TrustManager) {
                new X509TrustManagerExtensions((X509TrustManager)tm);
                return;
            }
        }
        fail();
    }
}