summaryrefslogtreecommitdiff
path: root/app/src/test/java/se/leap
diff options
context:
space:
mode:
authorFup Duck <fupduck@sacknagel.com>2018-01-21 18:01:26 +0100
committerFup Duck <fupduck@sacknagel.com>2018-01-21 18:01:26 +0100
commit6e45a5bcb4de152543b5dd5d9bd2027fb62f7375 (patch)
tree426b1e4ffe9578c106884ce6aef01d9dfa1ca56e /app/src/test/java/se/leap
parent3b6bc548f6197dfbd8a4e55524a3f6e0cdd224c0 (diff)
parentdf8b1fcf1ecc55f15229935294a337c897960ff4 (diff)
Merge remote-tracking branch '0xacab/0.9.8' into 8819_config_wizard_design
Diffstat (limited to 'app/src/test/java/se/leap')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/ConfigHelperTest.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/ConfigHelperTest.java b/app/src/test/java/se/leap/bitmaskclient/ConfigHelperTest.java
new file mode 100644
index 00000000..a9a5733d
--- /dev/null
+++ b/app/src/test/java/se/leap/bitmaskclient/ConfigHelperTest.java
@@ -0,0 +1,57 @@
+package se.leap.bitmaskclient;
+
+import android.content.SharedPreferences;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import se.leap.bitmaskclient.testutils.MockSharedPreferences;
+import se.leap.bitmaskclient.testutils.TestSetupHelper;
+
+import static org.junit.Assert.*;
+import static se.leap.bitmaskclient.Constants.PROVIDER_CONFIGURED;
+import static se.leap.bitmaskclient.testutils.TestSetupHelper.getInputAsString;
+
+/**
+ * Created by cyberta on 17.01.18.
+ */
+public class ConfigHelperTest {
+
+ private SharedPreferences mockPreferences;
+
+
+ @Before
+ public void setup() {
+ mockPreferences = new MockSharedPreferences();
+ }
+
+ @Test
+ public void providerInSharedPreferences_notInPreferences_returnsFalse() throws Exception {
+ assertFalse(ConfigHelper.providerInSharedPreferences(mockPreferences));
+ }
+
+ @Test
+ public void providerInSharedPreferences_inPreferences_returnsTrue() throws Exception {
+ mockPreferences.edit().putBoolean(PROVIDER_CONFIGURED, true).apply();
+ assertTrue(ConfigHelper.providerInSharedPreferences(mockPreferences));
+ }
+
+ @Test
+ public void getSavedProviderFromSharedPreferences_notInPreferences_returnsDefaultProvider() throws Exception {
+ Provider provider = ConfigHelper.getSavedProviderFromSharedPreferences(mockPreferences);
+ assertFalse(provider.isConfigured());
+ }
+
+ @Test
+ public void getSavedProviderFromSharedPreferences_notInPreferences_returnsConfiguredProvider() throws Exception {
+ mockPreferences.edit()
+ .putString(Provider.KEY, getInputAsString(getClass().getClassLoader().getResourceAsStream("riseup.net.json")))
+ .putString(Provider.MAIN_URL, "https://riseup.net")
+ .putString(Provider.CA_CERT, getInputAsString(getClass().getClassLoader().getResourceAsStream("riseup.net.pem")))
+ .apply();
+ Provider provider = ConfigHelper.getSavedProviderFromSharedPreferences(mockPreferences);
+ assertTrue(provider.isConfigured());
+ }
+
+
+} \ No newline at end of file