summaryrefslogtreecommitdiff
path: root/app/src/test/java
diff options
context:
space:
mode:
authorFup Duck <fupduck@sacknagel.com>2017-12-14 22:48:03 +0100
committerFup Duck <fupduck@sacknagel.com>2017-12-14 22:48:03 +0100
commit673c4221554fc92d87fa306c8a95cefb75693d78 (patch)
treec2e74c1ab1d42f05a27f64b6d915a39f639ee7dc /app/src/test/java
parentf10380f7d8bc85d8127328a9d9c092bc109bb340 (diff)
parent67ff3447f10c43770dc9ee4dccf358321063d131 (diff)
Merge remote-tracking branch '0xacab/0.9.8' into 0.9.8/sidebar
Diffstat (limited to 'app/src/test/java')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java96
1 files changed, 96 insertions, 0 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
new file mode 100644
index 00000000..15085b46
--- /dev/null
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/EipStatusTest.java
@@ -0,0 +1,96 @@
+package se.leap.bitmaskclient.eip;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import de.blinkt.openvpn.core.ConnectionStatus;
+import de.blinkt.openvpn.core.VpnStatus;
+import se.leap.bitmaskclient.R;
+
+import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_AUTH_FAILED;
+import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTED;
+import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET;
+import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTING_SERVER_REPLIED;
+import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_START;
+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 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;
+
+/**
+ * Created by cyberta on 06.12.17.
+ * TODO: Mock AsyncTask
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class EipStatusTest {
+
+ EipStatus eipStatus;
+
+ @Before
+ public void setUp() {
+ eipStatus = EipStatus.getInstance();
+
+ }
+
+ @Test
+ public void testUpdateState_LEVEL_CONNECTED() throws Exception {
+ eipStatus.updateState("CONNECTED", "", R.string.state_connected, LEVEL_CONNECTED );
+ assertTrue("LEVEL_CONNECTED eipLevel", eipStatus.getEipLevel() == EipStatus.EipLevel.CONNECTED);
+ assertTrue("LEVEL_CONNECTED level", eipStatus.getLevel() == LEVEL_CONNECTED);
+ assertTrue("LEVEL_CONNECTED localizedResId", eipStatus.getLocalizedResId() == R.string.state_connected);
+ 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_CONNECTING_SERVER_REPLIED() throws Exception {
+ eipStatus.updateState("ADD_ROUTES", "", 0, LEVEL_CONNECTING_SERVER_REPLIED );
+ assertTrue("LEVEL_CONNECTING_SERVER_REPLIED eipLevel", eipStatus.getEipLevel() == CONNECTING);
+ assertTrue("LEVEL_CONNECTING_SERVER_REPLIED level", eipStatus.getLevel() == LEVEL_CONNECTING_SERVER_REPLIED);
+ }
+
+ @Test
+ public void testUpdateState_LEVEL_CONNECTING_NO_SERVER_REPLY_YET() throws Exception {
+ eipStatus.updateState("ADD_ROUTES", "", 0, LEVEL_CONNECTING_NO_SERVER_REPLY_YET );
+ assertTrue("LEVEL_CONNECTING_SERVER_REPLIED eipLevel", eipStatus.getEipLevel() == CONNECTING);
+ assertTrue("LEVEL_CONNECTING_SERVER_REPLIED level", eipStatus.getLevel() == LEVEL_CONNECTING_NO_SERVER_REPLY_YET);
+ }
+ @Test
+ public void testUpdateState_LEVEL_START() throws Exception {
+ eipStatus.updateState("VPN_GENERATE_CONFIG", "", R.string.building_configration, ConnectionStatus.LEVEL_START);
+ assertTrue("LEVEL_START eipLevel", eipStatus.getEipLevel() == CONNECTING);
+ assertTrue("LEVEL_START level", eipStatus.getLevel() == LEVEL_START);
+ }
+
+ @Test
+ public void testUpdateState_LEVEL_WAITING_FOR_USER_INPUT() throws Exception {
+ eipStatus.updateState("NEED", "", 0, LEVEL_WAITING_FOR_USER_INPUT);
+ assertTrue("LEVEL_WAITING_FOR_USER_INPUT eipLevel", eipStatus.getEipLevel() == CONNECTING);
+ assertTrue("LEVEL_WAITING_FOR_USER_INPUT", eipStatus.getLevel() == LEVEL_WAITING_FOR_USER_INPUT);
+ }
+
+ @Test
+ public void testUpdateState_LEVEL_AUTH_FAILED() throws Exception {
+ eipStatus.updateState("AUTH_FAILED", "", R.string.state_auth_failed, ConnectionStatus.LEVEL_AUTH_FAILED);
+ assertTrue("AUTH_FAILED eipLevel", eipStatus.getEipLevel() == DISCONNECTED);
+ assertTrue("AUTH_FAILED level", eipStatus.getLevel() == LEVEL_AUTH_FAILED);
+ }
+
+
+ @Test
+ public void testUpdateState_UNKNOWN_LEVEL() throws Exception {
+ eipStatus.updateState("UNKNOWN", "", 0, ConnectionStatus.UNKNOWN_LEVEL);
+ assertTrue("UNKNOWN_LEVEL eipLevel", eipStatus.getEipLevel() == UNKNOWN);
+ assertTrue("UNKNOWN_LEVEL level", eipStatus.getLevel() == UNKNOWN_LEVEL);
+ }
+
+} \ No newline at end of file