summaryrefslogtreecommitdiff
path: root/app/src/test/java/se
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2022-11-14 21:40:09 +0100
committercyberta <cyberta@riseup.net>2022-11-22 01:48:38 +0100
commit24363464d6336ea3ac61bf4fe59b2e253676eaf2 (patch)
tree77cc3d85eed3909d51909221fc98ee8718744f5f /app/src/test/java/se
parentdbb32301d2cbd489c326b22cb0c43b885f9618a2 (diff)
fix tests
Diffstat (limited to 'app/src/test/java/se')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java34
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/testutils/MockSharedPreferences.java3
2 files changed, 36 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 c6ba1e6f..e14fa4c3 100644
--- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
+++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockHelper.java
@@ -12,11 +12,17 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_MOTD;
+import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_MOTD_HASHES;
+import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_MOTD_LAST_SEEN;
+import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_MOTD_LAST_UPDATED;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_PRIVATE_KEY;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_VPN_CERTIFICATE;
import static se.leap.bitmaskclient.base.utils.FileHelper.createFile;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getEipDefinitionFromPreferences;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getFromPersistedProvider;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getLongFromPersistedProvider;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getStringSetFromPersistedProvider;
import android.content.Context;
import android.content.Intent;
@@ -474,11 +480,39 @@ public class MockHelper {
return providerFromPrefs.getCaCert();
case Provider.GEOIP_URL:
return providerFromPrefs.getGeoipUrl().toString();
+ case Provider.MOTD_URL:
+ return providerFromPrefs.getMotdUrl().toString();
+ case PROVIDER_MOTD:
+ return providerFromPrefs.getMotdJsonString();
}
return null;
}
});
+ when(getLongFromPersistedProvider(anyString(), anyString(), any(SharedPreferences.class))).thenAnswer(new Answer<Long>() {
+ @Override
+ public Long answer(InvocationOnMock invocation) throws Throwable {
+ String key = (String) invocation.getArguments()[0];
+ switch (key) {
+ case PROVIDER_MOTD_LAST_SEEN:
+ return providerFromPrefs.getLastMotdSeen();
+ case PROVIDER_MOTD_LAST_UPDATED:
+ return providerFromPrefs.getLastMotdUpdate();
+ }
+ return 0L;
+ }
+ });
+ when(getStringSetFromPersistedProvider(anyString(), anyString(), any(SharedPreferences.class))).thenAnswer(new Answer<Set<String>>() {
+ @Override
+ public Set<String> answer(InvocationOnMock invocation) throws Throwable {
+ String key = (String) invocation.getArguments()[0];
+ switch (key) {
+ case PROVIDER_MOTD_HASHES:
+ return providerFromPrefs.getMotdLastSeenHashes();
+ }
+ return null;
+ }
+ });
}
public static void mockPreferenceHelper(MockSharedPreferences preferences) {
diff --git a/app/src/test/java/se/leap/bitmaskclient/testutils/MockSharedPreferences.java b/app/src/test/java/se/leap/bitmaskclient/testutils/MockSharedPreferences.java
index be0cf41f..4fabc2c0 100644
--- a/app/src/test/java/se/leap/bitmaskclient/testutils/MockSharedPreferences.java
+++ b/app/src/test/java/se/leap/bitmaskclient/testutils/MockSharedPreferences.java
@@ -21,6 +21,7 @@ import android.content.SharedPreferences;
import androidx.annotation.Nullable;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -48,7 +49,7 @@ public class MockSharedPreferences implements SharedPreferences {
@Nullable
@Override
public Set<String> getStringSet(String key, @Nullable Set<String> defValues) {
- return null;
+ return new HashSet<>();
}
@Override