summaryrefslogtreecommitdiff
path: root/app/src/test/java
diff options
context:
space:
mode:
authorFup Duck <fupduck@sacknagel.com>2018-02-13 11:31:18 +0100
committerFup Duck <fupduck@sacknagel.com>2018-02-13 11:31:18 +0100
commit3cc60ff642134e7442500e309c6b1248c819c0e8 (patch)
tree894e21a8863c1b53976c2d7948a5dc60381d937c /app/src/test/java
parent710fdd182dc1a470c949f50701d3aace4d67134c (diff)
8827 - add ProviderTest & DefaultedURLTest
Diffstat (limited to 'app/src/test/java')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/DefaultedURLTest.java31
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/ProviderTest.java21
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java30
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java1
4 files changed, 55 insertions, 28 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/DefaultedURLTest.java b/app/src/test/java/se/leap/bitmaskclient/DefaultedURLTest.java
new file mode 100644
index 00000000..cbf47621
--- /dev/null
+++ b/app/src/test/java/se/leap/bitmaskclient/DefaultedURLTest.java
@@ -0,0 +1,31 @@
+package se.leap.bitmaskclient;
+
+import org.junit.Test;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by cyberta on 11.02.18.
+ */
+public class DefaultedURLTest {
+
+ @Test
+ public void testEquals_false() throws MalformedURLException {
+ DefaultedURL defaultedURL = new DefaultedURL();
+ DefaultedURL customURL = new DefaultedURL();
+ customURL.setUrl(new URL("https://customurl.com"));
+
+ assertFalse(defaultedURL.equals(customURL));
+ }
+
+ @Test
+ public void testEquals_true() throws MalformedURLException {
+ DefaultedURL defaultedURL = new DefaultedURL();
+ DefaultedURL customURL = new DefaultedURL();
+ assertTrue(defaultedURL.equals(customURL));
+ }
+
+}
diff --git a/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java b/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java
new file mode 100644
index 00000000..794c3087
--- /dev/null
+++ b/app/src/test/java/se/leap/bitmaskclient/ProviderTest.java
@@ -0,0 +1,21 @@
+package se.leap.bitmaskclient;
+
+import org.junit.Test;
+
+import se.leap.bitmaskclient.testutils.TestSetupHelper;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Created by cyberta on 12.02.18.
+ */
+public class ProviderTest {
+
+ @Test
+ public void testEquals_sameFields_returnsTrue() throws Exception {
+ Provider p1 = TestSetupHelper.getConfiguredProvider();
+ Provider p2 = TestSetupHelper.getConfiguredProvider();
+ assertTrue("Providers should be same:", p1.equals(p2));
+ }
+
+}
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
index b0953493..4842d170 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
@@ -25,7 +25,6 @@ import android.os.Bundle;
import android.text.TextUtils;
import org.json.JSONException;
-import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,7 +35,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.io.IOException;
-import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateEncodingException;
@@ -64,7 +62,9 @@ import static se.leap.bitmaskclient.testutils.MockHelper.mockProviderApiConnecto
import static se.leap.bitmaskclient.testutils.MockHelper.mockResources;
import static se.leap.bitmaskclient.testutils.MockHelper.mockResultReceiver;
import static se.leap.bitmaskclient.testutils.MockHelper.mockTextUtils;
+import static se.leap.bitmaskclient.testutils.TestSetupHelper.getConfiguredProvider;
import static se.leap.bitmaskclient.testutils.TestSetupHelper.getInputAsString;
+import static se.leap.bitmaskclient.testutils.TestSetupHelper.getProvider;
/**
@@ -108,32 +108,6 @@ public class ProviderApiManagerTest {
mockResources = mockResources(getClass().getClassLoader().getResourceAsStream("error_messages.json"));
}
- private Provider getConfiguredProvider() throws IOException, JSONException {
- return getProvider(null, null, null);
- }
-
- private Provider getProvider(String domain, String caCertFile, String jsonFile) {
- if (domain == null)
- domain = "https://riseup.net";
- if (caCertFile == null)
- caCertFile = "riseup.net.pem";
- if (jsonFile == null)
- jsonFile = "riseup.net.json";
-
- try {
- return new Provider(
- new URL(domain),
- getInputAsString(getClass().getClassLoader().getResourceAsStream(caCertFile)),
- getInputAsString(getClass().getClassLoader().getResourceAsStream(jsonFile))
-
- );
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
@Test
public void test_handleIntentSetupProvider_noProviderMainURL() throws IOException, JSONException {
Provider provider = new Provider("");
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 3e66a07d..c2362c7b 100644
--- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
+++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
@@ -344,6 +344,7 @@ public class MockHelper {
}
public static void mockConfigHelper(String mockedFingerprint, final Provider providerFromPrefs) throws CertificateEncodingException, NoSuchAlgorithmException {
+ // FIXME use MockSharedPreferences instead of provider
mockStatic(ConfigHelper.class);
when(ConfigHelper.getFromPersistedProvider(anyString(), anyString(), any(SharedPreferences.class))).thenAnswer(new Answer<String>() {
@Override