diff options
Diffstat (limited to 'app/src/test/java')
3 files changed, 56 insertions, 1 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/base/utils/DateHelperTest.java b/app/src/test/java/se/leap/bitmaskclient/base/utils/DateHelperTest.java new file mode 100644 index 00000000..2651a64d --- /dev/null +++ b/app/src/test/java/se/leap/bitmaskclient/base/utils/DateHelperTest.java @@ -0,0 +1,20 @@ +package se.leap.bitmaskclient.base.utils; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class DateHelperTest { + + @Test + public void getFormattedDateWithTimezone() { + Pattern datePattern = Pattern.compile("^10 Nov 22 [1]?[0-9]:26 [+-][0-9]{4}$"); + String formattedDate = DateHelper.getFormattedDateWithTimezone(1668075969744L); + Matcher matcher = datePattern.matcher(formattedDate); + System.out.println(formattedDate); + assertTrue("date should be formatted similar to 10 Nov 22 11:26 +0100", matcher.find()); + } +}
\ No newline at end of file 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 |