How to resolve java.lang.AssertionError when creating OkHttpClient in mockito?
<p>I'm trying to make some canned network respones. I have the json response for the actual request and I have Retrofit interfaces that serialize responses. I am beyond frustrated trying to set this up. What should I be doing here? It seems my options are, 1) Use a MockWebServer() 2) Use a RequestInterceptor().</p>

<p>While trying to use either 1 or 2, I can't for the life of me instantiate an OkHttpClient() without it failing, basically this puts every thing I try to death immediately. I get an java.lang.AssertionError because OkHttpClient is throwing this when it can't find a TLS algorithm.</p>

<pre><code> if (builder.sslSocketFactory != null || !isTLS) {
      this.sslSocketFactory = builder.sslSocketFactory;
    } else {
      try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, null, null);
        this.sslSocketFactory = sslContext.getSocketFactory();
      } catch (GeneralSecurityException e) {
        **throw new AssertionError(); // The system has no TLS. Just give up.**
      }
    }
</code></pre>

<p>I've tried to keep the "javax.net.ssl" class in the android.jar using unMock, but that didn't resolve the error.</p>

<pre><code>unMock {
    // URI to download the android-all.jar from. e.g. https://oss.sonatype.org/content/groups/public/org/robolectric/android-all/
    downloadFrom 'https://oss.sonatype.org/content/groups/public/org/robolectric/android-all/4.3_r2-robolectric-0/android-all-4.3_r2-robolectric-0.jar'

    keep "android.util.Log"
    keep "javax.net.ssl"
}
</code></pre>

<p>So basically, I've come across various examples of how to mock network requests with retrofit 2, but I can't get past this hurdle, and I'm feeling pretty defeated. I haven't seen anyone else with this problem, and I'm baffled as to how everyone is easily instantiating new OkHttpClients in all their tests.</p>

<p>Here are the relevant dependencies I am using.</p>

<pre><code>    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-all:1.10.19'
    testCompile 'org.powermock:powermock-mockito-release-full:1.6.4'
    testCompile 'org.powermock:powermock-module-junit4:1.6.4'
    testCompile 'org.easymock:easymock:3.4'
    testCompile 'org.powermock:powermock-api-easymock:1.6.4'
    testCompile 'com.squareup.okhttp3:mockwebserver:3.2.0'

    compile 'com.squareup.retrofit2:retrofit:2.0.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
    compile 'com.google.code.gson:gson:2.4'
</code></pre>