Last active
February 1, 2017 01:36
-
-
Save ecgreb/d2c3e8552ae9b880a542ce60e123a15f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void initMockSslContext() throws KeyStoreException, NoSuchAlgorithmException { | |
final TrustManagerFactory trustManagerFactory = PowerMockito.mock(TrustManagerFactory.class); | |
final TrustManager[] trustManagers = new TrustManager[1]; | |
// Mock TrustManagerFactory.getInstance(String) | |
mockStatic(TrustManagerFactory.class); | |
when(TrustManagerFactory.getInstance(anyString())).thenReturn(trustManagerFactory); | |
// Mock TrustManagerFactory#getTrustManagers() | |
trustManagers[0] = PowerMockito.mock(X509TrustManager.class); | |
doNothing().when(trustManagerFactory).init(any(KeyStore.class)); | |
when(trustManagerFactory.getTrustManagers()).thenReturn(trustManagers); | |
// Mock SSLContext.getInstance(String) | |
mockStatic(SSLContext.class); | |
when(SSLContext.getInstance(anyString())).thenReturn(PowerMockito.mock(SSLContext.class)); | |
// Mock CertificateChainCleaner.get(X509TrustManager) | |
mockStatic(CertificateChainCleaner.class); | |
when(CertificateChainCleaner.get(any(X509TrustManager.class))) | |
.thenReturn(PowerMockito.mock(CertificateChainCleaner.class)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment