summaryrefslogtreecommitdiff
path: root/app/src/test/java/se/leap
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/test/java/se/leap')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java19
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java3
2 files changed, 14 insertions, 8 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java
index f332b094..8495f962 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java
@@ -3,14 +3,17 @@ package se.leap.bitmaskclient.eip;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.ConnectionStatus;
-import de.blinkt.openvpn.core.ProfileManager;
import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.testutils.MockHelper;
+import se.leap.bitmaskclient.testutils.TestSetupHelper;
+import se.leap.bitmaskclient.utils.PreferenceHelper;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_AUTH_FAILED;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTED;
@@ -21,6 +24,8 @@ import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_VPNPAUSED;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT;
import static de.blinkt.openvpn.core.ConnectionStatus.UNKNOWN_LEVEL;
import static junit.framework.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.powermock.api.mockito.PowerMockito.doNothing;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
import static se.leap.bitmaskclient.eip.EipStatus.EipLevel.CONNECTING;
@@ -32,7 +37,7 @@ import static se.leap.bitmaskclient.eip.EipStatus.EipLevel.UNKNOWN;
* TODO: Mock AsyncTask
*/
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ProfileManager.class})
+@PrepareForTest({PreferenceHelper.class})
public class EipStatusTest {
EipStatus eipStatus;
@@ -55,10 +60,11 @@ public class EipStatusTest {
@Test
public void testUpdateState_LEVEL_VPNPAUSED_hasPersistentTun() throws Exception {
- mockStatic(ProfileManager.class);
+ mockStatic(PreferenceHelper.class);
VpnProfile mockVpnProfile = new VpnProfile("mockProfile");
mockVpnProfile.mPersistTun = true;
- when(ProfileManager.getLastConnectedVpn()).thenReturn(mockVpnProfile);
+ doNothing().when(PreferenceHelper.class);
+ VpnStatus.setLastConnectedVpnProfile(null, mockVpnProfile);
VpnStatus.updateStateString("SCREENOFF", "", R.string.state_screenoff, LEVEL_VPNPAUSED);
assertTrue("LEVEL_VPN_PAUSED eipLevel", eipStatus.getEipLevel() == CONNECTING);
assertTrue("LEVEL_VPN_PAUSED level", eipStatus.getLevel() == LEVEL_VPNPAUSED);
@@ -67,10 +73,11 @@ public class EipStatusTest {
@Test
public void testUpdateState_LEVEL_VPNPAUSED_hasNotPersistentTun() throws Exception {
- mockStatic(ProfileManager.class);
+ mockStatic(PreferenceHelper.class);
VpnProfile mockVpnProfile = new VpnProfile("mockProfile");
mockVpnProfile.mPersistTun = false;
- when(ProfileManager.getLastConnectedVpn()).thenReturn(mockVpnProfile);
+ doNothing().when(PreferenceHelper.class);
+ VpnStatus.setLastConnectedVpnProfile(null, mockVpnProfile);
VpnStatus.updateStateString("SCREENOFF", "", R.string.state_screenoff, LEVEL_VPNPAUSED);
assertTrue("LEVEL_VPN_PAUSED eipLevel", eipStatus.getEipLevel() == DISCONNECTED);
assertTrue("LEVEL_VPN_PAUSED level", eipStatus.getLevel() == LEVEL_VPNPAUSED);
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 4726cab7..160e5ddd 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java
@@ -46,7 +46,6 @@ public class GatewaysManagerTest {
when(sharedPreferences.getString(eq(Constants.PROVIDER_PRIVATE_KEY), anyString())).thenReturn(secrets.getString(Constants.PROVIDER_PRIVATE_KEY));
when(sharedPreferences.getString(eq(Provider.CA_CERT), anyString())).thenReturn(secrets.getString(Provider.CA_CERT));
when(sharedPreferences.getString(eq(Constants.PROVIDER_VPN_CERTIFICATE), anyString())).thenReturn(secrets.getString(Constants.PROVIDER_VPN_CERTIFICATE));
- when(mockContext.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPreferences);
gatewaysManager = new GatewaysManager(mockContext, sharedPreferences);
@@ -74,7 +73,7 @@ public class GatewaysManagerTest {
String eipServiceJson = TestSetupHelper.getInputAsString(getClass().getClassLoader().getResourceAsStream("eip-service-two-gateways.json"));
gatewaysManager.fromEipServiceJson(new JSONObject(eipServiceJson));
assertEquals(2, gatewaysManager.size());
- gatewaysManager.clearGatewaysAndProfiles();
+ gatewaysManager.clearGateways();
assertEquals(0, gatewaysManager.size());
}