From 50be8fc874033b42762436f70329a89974c276df Mon Sep 17 00:00:00 2001 From: Rafa Hernandez Date: Wed, 11 Jul 2018 09:02:35 -0400 Subject: [PATCH] wip(tes): working on test Signed-off-by: Rafa Hernandez --- .../core/deeplink/DeepLinkModelRoboTest.java | 2 +- .../core/deeplink/DeeplinkModelTest.java | 6 +- .../core/enrollment/EnrollmentHelperTest.java | 67 ++++++++++++++----- .../core/enrollment/EnrollmentModelTest.java | 35 +++------- .../core/permission/PermissionModelTest.java | 29 +++----- .../mdm/agent/core/user/UserModelTest.java | 30 ++------- 6 files changed, 77 insertions(+), 92 deletions(-) diff --git a/app/src/test/java/org/flyve/mdm/agent/core/deeplink/DeepLinkModelRoboTest.java b/app/src/test/java/org/flyve/mdm/agent/core/deeplink/DeepLinkModelRoboTest.java index 17f59b5749..06dc946490 100644 --- a/app/src/test/java/org/flyve/mdm/agent/core/deeplink/DeepLinkModelRoboTest.java +++ b/app/src/test/java/org/flyve/mdm/agent/core/deeplink/DeepLinkModelRoboTest.java @@ -39,7 +39,7 @@ import static org.mockito.Mockito.mock; @RunWith(RobolectricTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 16, packageName = "org.flyve.mdm.agent") +@Config(constants = BuildConfig.class, sdk = 23) public class DeepLinkModelRoboTest { private Deeplink.Presenter presenter; diff --git a/app/src/test/java/org/flyve/mdm/agent/core/deeplink/DeeplinkModelTest.java b/app/src/test/java/org/flyve/mdm/agent/core/deeplink/DeeplinkModelTest.java index acea59fadb..b2f82f1a1f 100644 --- a/app/src/test/java/org/flyve/mdm/agent/core/deeplink/DeeplinkModelTest.java +++ b/app/src/test/java/org/flyve/mdm/agent/core/deeplink/DeeplinkModelTest.java @@ -13,9 +13,9 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/app/src/test/java/org/flyve/mdm/agent/core/enrollment/EnrollmentHelperTest.java b/app/src/test/java/org/flyve/mdm/agent/core/enrollment/EnrollmentHelperTest.java index 3b5e33229d..6ea9110a23 100644 --- a/app/src/test/java/org/flyve/mdm/agent/core/enrollment/EnrollmentHelperTest.java +++ b/app/src/test/java/org/flyve/mdm/agent/core/enrollment/EnrollmentHelperTest.java @@ -1,13 +1,13 @@ package org.flyve.mdm.agent.core.enrollment; -import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; +import junit.framework.Assert; -import org.junit.Assert; +import org.flyve.mdm.agent.core.Routes; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; /* * Copyright © 2018 Teclib. All rights reserved. @@ -35,30 +35,61 @@ * @link https://flyve-mdm.com * ------------------------------------------------------------------------------ */ -@RunWith(AndroidJUnit4.class) +@RunWith(MockitoJUnitRunner.class) +//@PrepareForTest( { ConnectionHTTP.class, Routes.class }) public class EnrollmentHelperTest { - private Context context; - private EnrollmentHelper enroll; + // private EnrollmentHelper enroll; + + @Mock + private Routes routes; @Before public void setUp() throws Exception { - context = InstrumentationRegistry.getTargetContext(); - enroll = new EnrollmentHelper(context); + //enroll = new EnrollmentHelper(RuntimeEnvironment.application); + //routes = new Routes(RuntimeEnvironment.application); + + //mockStatic(ConnectionHTTP.class); + +// when(ConnectionHTTP.getSyncWebData(routes.initSession(""), "GET", null)) +// .thenReturn("{\"session_token\": \"session_token_fake\"}"); +// +// when(ConnectionHTTP.getSyncWebData(routes.getFullSession(), "GET", null)) +// .thenReturn("{\"session\": {\"plugin_flyvemdm_guest_profiles_id\": \"9\"}}"); +// +// when(ConnectionHTTP.getSyncWebData(routes.changeActiveProfile(""), "GET", null)) +// .thenReturn("{\"session_token\": \"session_token_fake\"}"); + } @Test public void createX509certificateSuccess() throws Exception { - enroll.createX509cert(new EnrollmentHelper.EnrollCallBack() { - @Override - public void onSuccess(String data) { Assert.assertTrue(true); - } + // enroll.createX509cert(new EnrollmentHelper.EnrollCallBack() { +// @Override +// public void onSuccess(String data) { +// Assert.assertTrue(true); +// } +// +// @Override +// public void onError(String error) { +// Assert.assertTrue(false); +// } +// }); + } - @Override - public void onError(String error) { - Assert.assertTrue(false); - } - }); + @Test + public void getActiveSessionToken() { +// enroll.getActiveSessionToken(new EnrollmentHelper.EnrollCallBack() { +// @Override +// public void onSuccess(String data) { +// Assert.assertTrue(true); +// } +// +// @Override +// public void onError(String error) { +// Assert.assertTrue(false); +// } +// }); } } \ No newline at end of file diff --git a/app/src/test/java/org/flyve/mdm/agent/core/enrollment/EnrollmentModelTest.java b/app/src/test/java/org/flyve/mdm/agent/core/enrollment/EnrollmentModelTest.java index 78e074b507..bf4bb0a470 100644 --- a/app/src/test/java/org/flyve/mdm/agent/core/enrollment/EnrollmentModelTest.java +++ b/app/src/test/java/org/flyve/mdm/agent/core/enrollment/EnrollmentModelTest.java @@ -1,17 +1,15 @@ package org.flyve.mdm.agent.core.enrollment; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.rule.ActivityTestRule; -import org.flyve.mdm.agent.ui.EnrollmentActivity; -import org.junit.Assert; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; -import static android.support.test.InstrumentationRegistry.getInstrumentation; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; /* * Copyright © 2018 Teclib. All rights reserved. @@ -40,43 +38,30 @@ * ------------------------------------------------------------------------------ */ +@RunWith(MockitoJUnitRunner.class) public class EnrollmentModelTest { + @Mock private Context context; private EnrollmentModel model; - - @Rule - public ActivityTestRule rule = new ActivityTestRule<>(EnrollmentActivity.class); + private Enrollment.Presenter presenter; @Before public void setUp() { - context = InstrumentationRegistry.getTargetContext(); - Enrollment.Presenter presenter = mock(Enrollment.Presenter.class); + presenter = mock(Enrollment.Presenter.class); model = new EnrollmentModel(presenter); } @Test public void createInventory() { model.createInventory(context); - Assert.assertTrue(true); + verify(presenter).inventorySuccess(""); } @Test public void createX509certification() { model.createX509certification(context); - Assert.assertTrue(true); - } - - @Test - public void selectPhoto() { - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - model.selectPhoto(rule.getActivity(), 2, 1); - } - }); - - Assert.assertTrue(true); + verify(presenter).certificationX509Success(); } } \ No newline at end of file diff --git a/app/src/test/java/org/flyve/mdm/agent/core/permission/PermissionModelTest.java b/app/src/test/java/org/flyve/mdm/agent/core/permission/PermissionModelTest.java index 1437334301..36a1b7c36a 100644 --- a/app/src/test/java/org/flyve/mdm/agent/core/permission/PermissionModelTest.java +++ b/app/src/test/java/org/flyve/mdm/agent/core/permission/PermissionModelTest.java @@ -1,17 +1,13 @@ package org.flyve.mdm.agent.core.permission; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.rule.ActivityTestRule; -import org.flyve.mdm.agent.ui.EnrollmentActivity; -import org.junit.Assert; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; +import org.mockito.Mock; -import static android.support.test.InstrumentationRegistry.getInstrumentation; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; /* * Copyright © 2018 Teclib. All rights reserved. @@ -42,29 +38,20 @@ public class PermissionModelTest { + @Mock private Context context; private PermissionModel model; + private Permission.Presenter presenter; @Before public void setUp() { - context = InstrumentationRegistry.getTargetContext(); - Permission.Presenter presenter = mock(Permission.Presenter.class); + presenter = mock(Permission.Presenter.class); model = new PermissionModel(presenter); } - @Rule - public ActivityTestRule rule = new ActivityTestRule<>(EnrollmentActivity.class); - - @Test - public void showDialogShare() { - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - model.showDialogShare(rule.getActivity()); - } - }); - - Assert.assertTrue(true); + public void generateInventory() { + model.generateInventory(context); + verify(presenter).inventorySuccess(""); } } \ No newline at end of file diff --git a/app/src/test/java/org/flyve/mdm/agent/core/user/UserModelTest.java b/app/src/test/java/org/flyve/mdm/agent/core/user/UserModelTest.java index d6bd32b3f9..f3c5d24017 100644 --- a/app/src/test/java/org/flyve/mdm/agent/core/user/UserModelTest.java +++ b/app/src/test/java/org/flyve/mdm/agent/core/user/UserModelTest.java @@ -1,17 +1,13 @@ package org.flyve.mdm.agent.core.user; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.rule.ActivityTestRule; -import org.flyve.mdm.agent.ui.EnrollmentActivity; -import org.junit.Assert; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; +import org.mockito.Mock; -import static android.support.test.InstrumentationRegistry.getInstrumentation; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; /* * Copyright © 2018 Teclib. All rights reserved. @@ -42,34 +38,20 @@ public class UserModelTest { + @Mock private Context context; private UserModel model; - - @Rule - public ActivityTestRule rule = new ActivityTestRule<>(EnrollmentActivity.class); - + private User.Presenter presenter; @Before public void setUp() { - context = InstrumentationRegistry.getTargetContext(); - User.Presenter presenter = mock(User.Presenter.class); + presenter = mock(User.Presenter.class); model = new UserModel(presenter); } @Test public void load() { model.load(context); - Assert.assertTrue(true); - } - - @Test - public void selectPhoto() { - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - model.selectPhoto(rule.getActivity(), 1, 1); - } - }); - Assert.assertTrue(true); + verify(presenter).loadSuccess(new UserSchema()); } } \ No newline at end of file