diff options
Diffstat (limited to 'app/src')
3 files changed, 98 insertions, 2 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestDashboardIntegration.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestDashboardIntegration.java index faeb1791..ad2b4a00 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestDashboardIntegration.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestDashboardIntegration.java @@ -2,7 +2,7 @@ package se.leap.bitmaskclient.test; import java.io.*; -import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.R; public class TestDashboardIntegration extends BaseTestDashboardFragment { diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java index f5cb2260..3b0daf9a 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/UserStatusTestController.java @@ -4,7 +4,7 @@ import android.view.*; import com.robotium.solo.*; -import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.R; import static junit.framework.Assert.assertTrue; 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 |