diff options
author | cyBerta <cyberta@riseup.net> | 2018-02-27 20:48:13 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2018-02-27 20:48:13 +0100 |
commit | 69d7e4bc6d77e40407a404606b55630c35a4050b (patch) | |
tree | ae032982d0f5354f46927d3fb0f78bc331af5dfb /app/src/test/java | |
parent | e9c52ffc7965c96841f6ae573b19a0a0e9fc7b71 (diff) | |
parent | 96bc3f8d14cab11e43fbe6b11dfb6dbf46e5919b (diff) |
Merge branch 'origin_0.9.8'0.9.8
Diffstat (limited to 'app/src/test/java')
-rw-r--r-- | app/src/test/java/se/leap/bitmaskclient/ProviderTest.java | 30 | ||||
-rw-r--r-- | app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java | 15 |
2 files changed, 44 insertions, 1 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java b/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java index 794c3087..495d5b3f 100644 --- a/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java @@ -1,9 +1,15 @@ package se.leap.bitmaskclient; +import org.json.JSONException; import org.junit.Test; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + import se.leap.bitmaskclient.testutils.TestSetupHelper; +import static junit.framework.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** @@ -18,4 +24,28 @@ public class ProviderTest { assertTrue("Providers should be same:", p1.equals(p2)); } + @Test + public void testEquals_sameFields_returnsFalse() throws Exception { + Provider p1 = TestSetupHelper.getConfiguredProvider(); + Provider p2 = TestSetupHelper.getConfiguredProvider(); + p2.setMainUrl("http://somethingsdiffer.org"); + assertFalse("Providers should be same:", p1.equals(p2)); + } + + // see ProviderManagerTest testing add(...) + @Test + public void testEqualsThroughSetContains_differentFields_returnsFalse() throws Exception { + Provider p1 = TestSetupHelper.getConfiguredProvider(); + Provider p2 = TestSetupHelper.getConfiguredProvider(); + p2.setMainUrl("http://somethingsdiffer.org"); + Provider p3 = new Provider("https://anotherprovider.net"); + + Set<Provider> defaultProviders = new HashSet<>(); + defaultProviders.add(p1); + defaultProviders.add(p2); + + assertTrue(defaultProviders.contains(p1)); + assertTrue(defaultProviders.contains(p2)); + assertFalse(defaultProviders.contains(p3)); + } } 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); |