diff options
author | cyBerta <cyberta@riseup.net> | 2018-02-21 15:00:40 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2018-02-21 15:00:40 +0100 |
commit | 8e23cc34861f1b9fe5e04cdcf24563ffedf568b0 (patch) | |
tree | 1dd354191549b8f72e756816697c237f2ed30610 /app/src/test/java/se/leap | |
parent | e4f4521f9d50aad80a7c689eb949e75d1b521bac (diff) |
#8858 write tests for ProviderManager and some related refactorings
Diffstat (limited to 'app/src/test/java/se/leap')
-rw-r--r-- | app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java index c2362c7b..d85b050f 100644 --- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java +++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java @@ -14,6 +14,7 @@ import org.json.JSONObject; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.security.NoSuchAlgorithmException; @@ -29,7 +30,6 @@ import java.util.Set; import okhttp3.OkHttpClient; import se.leap.bitmaskclient.ConfigHelper; -import se.leap.bitmaskclient.Constants; import se.leap.bitmaskclient.OkHttpClientGenerator; import se.leap.bitmaskclient.Provider; import se.leap.bitmaskclient.R; @@ -343,6 +343,18 @@ public class MockHelper { return resultReceiver; } + public static void mockConfigHelperForFileInputStream() throws FileNotFoundException { + mockStatic(ConfigHelper.class); + when(ConfigHelper.loadInputStreamAsString(any(InputStream.class))).thenCallRealMethod(); + when(ConfigHelper.getInputStreamFrom(anyString())).thenAnswer(new Answer<InputStream>() { + @Override + public InputStream answer(InvocationOnMock invocation) throws Throwable { + String filename = (String) invocation.getArguments()[0]; + return getClass().getClassLoader().getResourceAsStream(filename); + } + }); + } + public static void mockConfigHelper(String mockedFingerprint, final Provider providerFromPrefs) throws CertificateEncodingException, NoSuchAlgorithmException { // FIXME use MockSharedPreferences instead of provider mockStatic(ConfigHelper.class); @@ -366,6 +378,7 @@ public class MockHelper { when(ConfigHelper.getFingerprintFromCertificate(any(X509Certificate.class), anyString())).thenReturn(mockedFingerprint); when(ConfigHelper.checkErroneousDownload(anyString())).thenCallRealMethod(); when(ConfigHelper.parseX509CertificateFromString(anyString())).thenCallRealMethod(); + when(ConfigHelper.loadInputStreamAsString(any(InputStream.class))).thenCallRealMethod(); } public static void mockFingerprintForCertificate(String mockedFingerprint) throws CertificateEncodingException, NoSuchAlgorithmException { mockStatic(ConfigHelper.class); |