summaryrefslogtreecommitdiff
path: root/app/src/test
diff options
context:
space:
mode:
authorFup Duck <fupduck@sacknagel.com>2018-02-13 10:35:10 +0100
committerFup Duck <fupduck@sacknagel.com>2018-02-13 10:35:10 +0100
commitfd9b6bd4069ab73eed6f3dfc697d1589ab5c9874 (patch)
tree0a88587ba084c1e62fa01b6649e2383744db2f05 /app/src/test
parent24788afa45ff46616b41626e7607d4461ab77387 (diff)
parentba1d730c12a5168c3a261604e0efd3b77ba3ec5b (diff)
Merge branch 'leap_0.9.8' into 8827_handle_switch_provider
Diffstat (limited to 'app/src/test')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java35
1 files changed, 30 insertions, 5 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 15085b46..f332b094 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java
@@ -3,9 +3,12 @@ package se.leap.bitmaskclient.eip;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
+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;
@@ -18,6 +21,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.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
import static se.leap.bitmaskclient.eip.EipStatus.EipLevel.CONNECTING;
import static se.leap.bitmaskclient.eip.EipStatus.EipLevel.DISCONNECTED;
import static se.leap.bitmaskclient.eip.EipStatus.EipLevel.UNKNOWN;
@@ -26,7 +31,8 @@ import static se.leap.bitmaskclient.eip.EipStatus.EipLevel.UNKNOWN;
* Created by cyberta on 06.12.17.
* TODO: Mock AsyncTask
*/
-@RunWith(MockitoJUnitRunner.class)
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ProfileManager.class})
public class EipStatusTest {
EipStatus eipStatus;
@@ -46,9 +52,28 @@ public class EipStatusTest {
assertTrue("LEVEL_CONNECTED state", eipStatus.getState().equals("CONNECTED"));
}
- @Test(expected= IllegalStateException.class)
- public void testUpdateState_LEVEL_VPNPAUSED() throws Exception {
- VpnStatus.updateStateString("USERPAUSE", "", R.string.state_userpause, LEVEL_VPNPAUSED);
+ @Test
+ public void testUpdateState_LEVEL_VPNPAUSED_hasPersistentTun() throws Exception {
+
+ mockStatic(ProfileManager.class);
+ VpnProfile mockVpnProfile = new VpnProfile("mockProfile");
+ mockVpnProfile.mPersistTun = true;
+ when(ProfileManager.getLastConnectedVpn()).thenReturn(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);
+ }
+
+ @Test
+ public void testUpdateState_LEVEL_VPNPAUSED_hasNotPersistentTun() throws Exception {
+
+ mockStatic(ProfileManager.class);
+ VpnProfile mockVpnProfile = new VpnProfile("mockProfile");
+ mockVpnProfile.mPersistTun = false;
+ when(ProfileManager.getLastConnectedVpn()).thenReturn(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);
}
@Test