Skip to content

Commit

Permalink
Update CoreLibrary tearDown methods
Browse files Browse the repository at this point in the history
  • Loading branch information
qiarie committed Feb 9, 2023
1 parent 4e5c86d commit 5b0be55
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public void initP2pLibrary() {

@Test(expected = IllegalStateException.class)
public void getInstanceShouldThrowException() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);

CoreLibrary.destroyInstance();
CoreLibrary.getInstance();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 - [email protected] on 18-08-2020.
*/
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
*/
Expand All @@ -34,7 +33,7 @@ public void setUp() {

@After
public void tearDown() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -66,7 +65,7 @@ public void setUp() {

@After
public void tearDown() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public void processFieldShouldCreateCaseBasedOnObsValueFilled() {

@After
public void tearDown() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
clientProcessor = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -354,6 +353,6 @@ public void testGetLocationHierarchyReturnsTreeForValidParentLocationId() {

@After
public void tearDown() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,6 @@ public void testPopulateValidatedEventsInfoAddInvalidEventsCountWhenStatusIsInva

@After
public void destroy() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -44,7 +44,7 @@ public class BarcodeScanActivityTest extends BaseUnitTest {

@BeforeClass
public static void resetCoreLibrary() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class BaseLoginActivityTest extends BaseRobolectricUnitTest {

@BeforeClass
public static void resetCoreLibrary() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
}

@Before
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -93,7 +92,7 @@ public void setUp() {

@After
public void tearDown() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
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;
import org.junit.Test;
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.
*/
Expand All @@ -47,7 +47,7 @@ public class FormActivityTest extends BaseUnitTest {

@BeforeClass
public static void resetCoreLibrarySingleton() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class SecuredActivityTest extends BaseRobolectricUnitTest {

@BeforeClass
public static void resetCoreLibrary() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
}

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,7 +150,7 @@ public void setUp() {

@After
public void tearDown() {
ReflectionHelpers.setStaticField(CoreLibrary.class, "instance", null);
CoreLibrary.destroyInstance();
}

@Test
Expand Down
Loading

0 comments on commit 5b0be55

Please sign in to comment.