summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java4
-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
3 files changed, 36 insertions, 5 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
index b0f3d09f..53f864cf 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java
@@ -30,7 +30,6 @@ import static se.leap.bitmaskclient.providersetup.ProviderAPI.ERRORS;
import android.os.Parcel;
import android.os.Parcelable;
-import android.util.Log;
import androidx.annotation.NonNull;
@@ -302,10 +301,7 @@ public final class Provider implements Parcelable {
public void setMotdUrl(String url) {
try {
this.motdUrl.setUrl(new URL(url));
- Log.d("PROVIDER", "setMotdUrl provider: " + this.domain + " - motd url: " + motdUrl.toString());
} catch (MalformedURLException e) {
- e.printStackTrace();
- Log.d("PROVIDER", "setMotdUrl exception!!! provider: " + this.domain + " - motd url: " + motdUrl.toString() + " obj:" + this.toString());
this.motdUrl = new DefaultedURL();
}
}
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