diff --git a/README.md b/README.md index 63b63095e..b1f2e8da5 100644 --- a/README.md +++ b/README.md @@ -314,4 +314,4 @@ By placing a file named `app.properties` in your implementation assets folder (S | `encrypt.shared.preferences` | Boolean | false | Enable/disables encrypting SharedPreferences | | `allow.offline.login.with.invalid.token` | Boolean | false | Allow offline login when token is no longer valid after a successful login when online and user is forcefully logged out | | `enable.search.button` | Boolean | false | Enable/Disable search to be triggered only after clicking the search icon in `org.smartregister.view.fragment.BaseRegisterFragment` or its subclass | -| `feature.profile.images.disabled` | Boolean | false | Disable profile image capturing and rendering | \ No newline at end of file +| `feature.profile.images.disabled` | Boolean | false | Disable profile image capturing and rendering | \ No newline at end of file diff --git a/opensrp-core/src/test/java/org/smartregister/CoreLibraryTest.java b/opensrp-core/src/test/java/org/smartregister/CoreLibraryTest.java index f1585ca0e..12adff3a5 100644 --- a/opensrp-core/src/test/java/org/smartregister/CoreLibraryTest.java +++ b/opensrp-core/src/test/java/org/smartregister/CoreLibraryTest.java @@ -74,8 +74,7 @@ public void initP2pLibrary() { @Test(expected = IllegalStateException.class) public void getInstanceShouldThrowException() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); - + CoreLibrary.destroyInstance(); CoreLibrary.getInstance(); } diff --git a/opensrp-core/src/test/java/org/smartregister/TestP2pApplication.java b/opensrp-core/src/test/java/org/smartregister/TestP2pApplication.java index 7b3f64647..c92f9cc19 100644 --- a/opensrp-core/src/test/java/org/smartregister/TestP2pApplication.java +++ b/opensrp-core/src/test/java/org/smartregister/TestP2pApplication.java @@ -1,10 +1,9 @@ package org.smartregister; -import org.robolectric.util.ReflectionHelpers; -import org.smartregister.repository.AllSharedPreferences; - import static android.preference.PreferenceManager.getDefaultSharedPreferences; +import org.smartregister.repository.AllSharedPreferences; + /** * Created by Ephraim Kigamba - nek.eam@gmail.com on 18-08-2020. */ @@ -18,7 +17,7 @@ public void onCreate() { AllSharedPreferences allSharedPreferences = new AllSharedPreferences(getDefaultSharedPreferences(context.applicationContext())); allSharedPreferences.updateANMUserName("demo"); - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); CoreLibrary.init(context, new TestSyncConfiguration(), 1588062490000l, new P2POptions(true)); } } diff --git a/opensrp-core/src/test/java/org/smartregister/login/model/BaseLoginModelTest.java b/opensrp-core/src/test/java/org/smartregister/login/model/BaseLoginModelTest.java index e66804594..22a890173 100644 --- a/opensrp-core/src/test/java/org/smartregister/login/model/BaseLoginModelTest.java +++ b/opensrp-core/src/test/java/org/smartregister/login/model/BaseLoginModelTest.java @@ -1,14 +1,5 @@ package org.smartregister.login.model; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.robolectric.util.ReflectionHelpers; -import org.smartregister.BaseRobolectricUnitTest; -import org.smartregister.Context; -import org.smartregister.CoreLibrary; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -17,6 +8,14 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.smartregister.BaseRobolectricUnitTest; +import org.smartregister.Context; +import org.smartregister.CoreLibrary; + /** * Created by samuelgithengi on 8/18/20. */ @@ -34,7 +33,7 @@ public void setUp() { @After public void tearDown() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } @Test diff --git a/opensrp-core/src/test/java/org/smartregister/login/presenter/BaseLoginPresenterTest.java b/opensrp-core/src/test/java/org/smartregister/login/presenter/BaseLoginPresenterTest.java index 0c2f94e6c..8f9e7aca5 100644 --- a/opensrp-core/src/test/java/org/smartregister/login/presenter/BaseLoginPresenterTest.java +++ b/opensrp-core/src/test/java/org/smartregister/login/presenter/BaseLoginPresenterTest.java @@ -1,5 +1,16 @@ package org.smartregister.login.presenter; +import static android.preference.PreferenceManager.getDefaultSharedPreferences; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + import android.content.res.Configuration; import android.view.ViewTreeObserver; import android.widget.RelativeLayout; @@ -15,7 +26,6 @@ import org.mockito.Spy; import org.powermock.reflect.Whitebox; import org.robolectric.Robolectric; -import org.robolectric.util.ReflectionHelpers; import org.smartregister.BaseRobolectricUnitTest; import org.smartregister.CoreLibrary; import org.smartregister.R; @@ -25,17 +35,6 @@ import java.lang.ref.WeakReference; -import static android.preference.PreferenceManager.getDefaultSharedPreferences; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - /** * Created by samuelgithengi on 8/18/20. */ @@ -66,7 +65,7 @@ public void setUp() { @After public void tearDown() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } @Test diff --git a/opensrp-core/src/test/java/org/smartregister/sync/ClientProcessorForJavaTest.java b/opensrp-core/src/test/java/org/smartregister/sync/ClientProcessorForJavaTest.java index 4dc3ad47e..ac1a36693 100644 --- a/opensrp-core/src/test/java/org/smartregister/sync/ClientProcessorForJavaTest.java +++ b/opensrp-core/src/test/java/org/smartregister/sync/ClientProcessorForJavaTest.java @@ -651,7 +651,7 @@ public void processFieldShouldCreateCaseBasedOnObsValueFilled() { @After public void tearDown() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); clientProcessor = null; } } diff --git a/opensrp-core/src/test/java/org/smartregister/sync/helper/BaseHelperTest.java b/opensrp-core/src/test/java/org/smartregister/sync/helper/BaseHelperTest.java index 7bab700ea..1af2c2b37 100644 --- a/opensrp-core/src/test/java/org/smartregister/sync/helper/BaseHelperTest.java +++ b/opensrp-core/src/test/java/org/smartregister/sync/helper/BaseHelperTest.java @@ -26,6 +26,6 @@ public void getFormattedBaseUrl() { Assert.assertEquals("http://site.com", new BaseHelper().getFormattedBaseUrl()); // Return the configuration to the previous state to fix the TaskServiceHelperTest failures - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } } \ No newline at end of file diff --git a/opensrp-core/src/test/java/org/smartregister/sync/helper/LocationServiceHelperTest.java b/opensrp-core/src/test/java/org/smartregister/sync/helper/LocationServiceHelperTest.java index 5465c7792..420d4e610 100644 --- a/opensrp-core/src/test/java/org/smartregister/sync/helper/LocationServiceHelperTest.java +++ b/opensrp-core/src/test/java/org/smartregister/sync/helper/LocationServiceHelperTest.java @@ -1,5 +1,15 @@ package org.smartregister.sync.helper; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.smartregister.AllConstants.OPERATIONAL_AREAS; +import static org.smartregister.sync.helper.LocationServiceHelper.LOCATION_LAST_SYNC_DATE; + import com.google.gson.reflect.TypeToken; import net.sqlcipher.database.SQLiteDatabase; @@ -13,7 +23,6 @@ import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; import org.powermock.reflect.Whitebox; import org.robolectric.util.ReflectionHelpers; import org.smartregister.BaseRobolectricUnitTest; @@ -41,16 +50,6 @@ import java.util.Collections; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.smartregister.AllConstants.OPERATIONAL_AREAS; -import static org.smartregister.sync.helper.LocationServiceHelper.LOCATION_LAST_SYNC_DATE; - public class LocationServiceHelperTest extends BaseRobolectricUnitTest { @Mock @@ -354,6 +353,6 @@ public void testGetLocationHierarchyReturnsTreeForValidParentLocationId() { @After public void tearDown() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } } \ No newline at end of file diff --git a/opensrp-core/src/test/java/org/smartregister/util/StatsUtilsTest.java b/opensrp-core/src/test/java/org/smartregister/util/StatsUtilsTest.java index 523cd234b..9b7f85264 100644 --- a/opensrp-core/src/test/java/org/smartregister/util/StatsUtilsTest.java +++ b/opensrp-core/src/test/java/org/smartregister/util/StatsUtilsTest.java @@ -143,6 +143,6 @@ public void testPopulateValidatedEventsInfoAddInvalidEventsCountWhenStatusIsInva @After public void destroy() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } } diff --git a/opensrp-core/src/test/java/org/smartregister/view/activity/BarcodeScanActivityTest.java b/opensrp-core/src/test/java/org/smartregister/view/activity/BarcodeScanActivityTest.java index 8bdf1c95a..4585c91fd 100644 --- a/opensrp-core/src/test/java/org/smartregister/view/activity/BarcodeScanActivityTest.java +++ b/opensrp-core/src/test/java/org/smartregister/view/activity/BarcodeScanActivityTest.java @@ -1,9 +1,13 @@ package org.smartregister.view.activity; +import static org.mockito.Mockito.verify; + import android.content.Intent; import android.util.Log; import android.util.SparseArray; +import androidx.test.core.app.ApplicationProvider; + import com.google.android.gms.vision.Detector; import com.google.android.gms.vision.barcode.Barcode; @@ -15,15 +19,11 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.robolectric.Robolectric; -import androidx.test.core.app.ApplicationProvider; import org.robolectric.android.controller.ActivityController; -import org.robolectric.util.ReflectionHelpers; import org.smartregister.BaseUnitTest; import org.smartregister.CoreLibrary; import org.smartregister.view.activity.mock.BarcodeScanActivityMock; -import static org.mockito.Mockito.verify; - public class BarcodeScanActivityTest extends BaseUnitTest { private BarcodeScanActivityMock barcodeScanActivity; @@ -44,7 +44,7 @@ public class BarcodeScanActivityTest extends BaseUnitTest { @BeforeClass public static void resetCoreLibrary() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } @Before diff --git a/opensrp-core/src/test/java/org/smartregister/view/activity/BaseLoginActivityTest.java b/opensrp-core/src/test/java/org/smartregister/view/activity/BaseLoginActivityTest.java index 8b22ebfe1..7c6867ab6 100644 --- a/opensrp-core/src/test/java/org/smartregister/view/activity/BaseLoginActivityTest.java +++ b/opensrp-core/src/test/java/org/smartregister/view/activity/BaseLoginActivityTest.java @@ -54,7 +54,7 @@ public class BaseLoginActivityTest extends BaseRobolectricUnitTest { @BeforeClass public static void resetCoreLibrary() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } @Before diff --git a/opensrp-core/src/test/java/org/smartregister/view/activity/BaseRegisterActivityTest.java b/opensrp-core/src/test/java/org/smartregister/view/activity/BaseRegisterActivityTest.java index d532197c0..b77cb77dd 100644 --- a/opensrp-core/src/test/java/org/smartregister/view/activity/BaseRegisterActivityTest.java +++ b/opensrp-core/src/test/java/org/smartregister/view/activity/BaseRegisterActivityTest.java @@ -1,5 +1,22 @@ package org.smartregister.view.activity; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; +import static org.robolectric.Shadows.shadowOf; +import static org.smartregister.view.activity.BaseRegisterActivity.BASE_REG_POSITION; + import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; @@ -23,7 +40,6 @@ import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowActivity; import org.robolectric.shadows.ShadowToast; -import org.robolectric.util.ReflectionHelpers; import org.smartregister.AllConstants; import org.smartregister.AllConstants.BARCODE; import org.smartregister.BaseRobolectricUnitTest; @@ -44,23 +60,6 @@ import java.util.UUID; import java.util.concurrent.Executors; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; -import static org.robolectric.Shadows.shadowOf; -import static org.smartregister.view.activity.BaseRegisterActivity.BASE_REG_POSITION; - /** * Created by samuelgithengi on 6/30/20. */ @@ -93,7 +92,7 @@ public void setUp() { @After public void tearDown() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } @Test diff --git a/opensrp-core/src/test/java/org/smartregister/view/activity/FormActivityTest.java b/opensrp-core/src/test/java/org/smartregister/view/activity/FormActivityTest.java index 2dc94823e..6ad6a1467 100644 --- a/opensrp-core/src/test/java/org/smartregister/view/activity/FormActivityTest.java +++ b/opensrp-core/src/test/java/org/smartregister/view/activity/FormActivityTest.java @@ -1,8 +1,16 @@ package org.smartregister.view.activity; +import static org.mockito.Mockito.when; +import static org.smartregister.AllConstants.ENTITY_ID_PARAM; +import static org.smartregister.AllConstants.FIELD_OVERRIDES_PARAM; +import static org.smartregister.AllConstants.FORM_NAME_PARAM; +import static org.smartregister.view.activity.NativeECSmartRegisterActivityTest.locationJson; + import android.content.Context; import android.content.Intent; +import androidx.test.core.app.ApplicationProvider; + import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -10,21 +18,13 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.robolectric.Robolectric; -import androidx.test.core.app.ApplicationProvider; import org.robolectric.android.controller.ActivityController; -import org.robolectric.util.ReflectionHelpers; import org.smartregister.BaseUnitTest; import org.smartregister.CoreLibrary; import org.smartregister.service.ZiggyService; import org.smartregister.view.activity.mock.FormActivityMock; import org.smartregister.view.controller.ANMLocationController; -import static org.mockito.Mockito.when; -import static org.smartregister.AllConstants.ENTITY_ID_PARAM; -import static org.smartregister.AllConstants.FIELD_OVERRIDES_PARAM; -import static org.smartregister.AllConstants.FORM_NAME_PARAM; -import static org.smartregister.view.activity.NativeECSmartRegisterActivityTest.locationJson; - /** * Created by kaderchowdhury on 12/11/17. */ @@ -47,7 +47,7 @@ public class FormActivityTest extends BaseUnitTest { @BeforeClass public static void resetCoreLibrarySingleton() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } @Before diff --git a/opensrp-core/src/test/java/org/smartregister/view/activity/SecuredActivityTest.java b/opensrp-core/src/test/java/org/smartregister/view/activity/SecuredActivityTest.java index 0c42a86c3..19c6090ba 100644 --- a/opensrp-core/src/test/java/org/smartregister/view/activity/SecuredActivityTest.java +++ b/opensrp-core/src/test/java/org/smartregister/view/activity/SecuredActivityTest.java @@ -64,7 +64,7 @@ public class SecuredActivityTest extends BaseRobolectricUnitTest { @BeforeClass public static void resetCoreLibrary() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } @Before diff --git a/opensrp-core/src/test/java/org/smartregister/view/fragment/BaseRegisterFragmentTest.java b/opensrp-core/src/test/java/org/smartregister/view/fragment/BaseRegisterFragmentTest.java index 5de3f7abf..0b4b8a00c 100644 --- a/opensrp-core/src/test/java/org/smartregister/view/fragment/BaseRegisterFragmentTest.java +++ b/opensrp-core/src/test/java/org/smartregister/view/fragment/BaseRegisterFragmentTest.java @@ -34,7 +34,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.robolectric.Robolectric; -import androidx.test.core.app.ApplicationProvider; import org.robolectric.util.ReflectionHelpers; import org.smartregister.AllConstants; import org.smartregister.BaseUnitTest; @@ -151,7 +150,7 @@ public void setUp() { @After public void tearDown() { - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); + CoreLibrary.destroyInstance(); } @Test diff --git a/opensrp-core/src/test/java/org/smartregister/view/receiver/ConnectivityChangeReceiverTest.java b/opensrp-core/src/test/java/org/smartregister/view/receiver/ConnectivityChangeReceiverTest.java index 3e65fbe9f..5e8ad2eeb 100644 --- a/opensrp-core/src/test/java/org/smartregister/view/receiver/ConnectivityChangeReceiverTest.java +++ b/opensrp-core/src/test/java/org/smartregister/view/receiver/ConnectivityChangeReceiverTest.java @@ -6,12 +6,13 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; +import androidx.test.core.app.ApplicationProvider; + import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; -import androidx.test.core.app.ApplicationProvider; import org.robolectric.Shadows; import org.robolectric.shadows.ShadowAlarmManager; import org.robolectric.util.ReflectionHelpers; @@ -44,8 +45,7 @@ public void tearDown(){ Session session = ReflectionHelpers.getField(CoreLibrary.getInstance().context().userService(), "session"); session.setPassword(null); session.start(0); - ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null); - + CoreLibrary.destroyInstance(); } @Test