diff options
author | cyBerta <cyberta@riseup.net> | 2021-03-20 16:57:31 +0100 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2021-04-22 22:53:01 +0200 |
commit | 1d2e09736a0526c574fe4c541d2f83c1ef44ccc0 (patch) | |
tree | 733e554ec5c784d6a36b581793d19a8876c50fa7 /app/src/test/java | |
parent | 5c4960cdb37b42ac82d22288e6de946e230b4a7b (diff) |
write tests for city based gateway selection
Diffstat (limited to 'app/src/test/java')
-rw-r--r-- | app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java index 6056f764..69c54db9 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java @@ -233,6 +233,41 @@ public class GatewaysManagerTest { } + @Test + public void testSelectN_selectFromCity_returnsGatewaysInPresortedOrder() { + Provider provider = getProvider(null, null, null, null, null, null, "v4/riseup_eipservice_for_geoip_v4.json", "v4/riseup_geoip_v4.json"); + + MockHelper.mockProviderObserver(provider); + //use openvpn, not pluggable transports + mockStatic(PreferenceHelper.class); + when(PreferenceHelper.getUsePluggableTransports(any(Context.class))).thenReturn(false); + when(PreferenceHelper.getPreferredCity(any(Context.class))).thenReturn("Paris"); + GatewaysManager gatewaysManager = new GatewaysManager(mockContext); + + assertEquals("mouette.riseup.net", gatewaysManager.select(0).getHost()); + assertEquals("hoatzin.riseup.net", gatewaysManager.select(1).getHost()); + assertEquals("zarapito.riseup.net", gatewaysManager.select(2).getHost()); + } + + @Test + public void testSelectN_selectFromCityWithTimezoneCalculation_returnsRandomizedGatewaysOfSelectedCity() { + Provider provider = getProvider(null, null, null, null, null, null, "v4/riseup_eipservice_for_geoip_v4.json", null); + + provider.setGeoIpJson(new JSONObject()); + MockHelper.mockProviderObserver(provider); + //use openvpn, not pluggable transports + mockStatic(PreferenceHelper.class); + when(PreferenceHelper.getUsePluggableTransports(any(Context.class))).thenReturn(false); + when(PreferenceHelper.getPreferredCity(any(Context.class))).thenReturn("Paris"); + GatewaysManager gatewaysManager = new GatewaysManager(mockContext); + + assertEquals("Paris", gatewaysManager.select(0).getName()); + assertEquals("Paris", gatewaysManager.select(1).getName()); + assertEquals("Paris", gatewaysManager.select(2).getName()); + assertEquals(null, gatewaysManager.select(3)); + } + + private String getJsonStringFor(String filename) throws IOException { return TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream(filename)); } |