Skip to content

Commit

Permalink
Migrate deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Jun 21, 2022
1 parent ac64bf0 commit bd33eeb
Show file tree
Hide file tree
Showing 35 changed files with 451 additions and 435 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.annotation.NonNull;

import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
Expand Down Expand Up @@ -49,7 +50,7 @@ public void mockImmunizationLibrary(@NonNull ImmunizationLibrary immunizationLib
PowerMockito.when(ImmunizationLibrary.getInstance().getVaccines(IMConstants.VACCINE_TYPE.CHILD)).thenReturn(VaccineRepo.Vaccine.values());
PowerMockito.when(ImmunizationLibrary.getInstance().getVaccines(IMConstants.VACCINE_TYPE.WOMAN)).thenReturn(VaccineRepo.Vaccine.values());

PowerMockito.when(ImmunizationLibrary.getInstance().vaccineRepository().findByEntityId(org.mockito.ArgumentMatchers.anyString())).thenReturn(null);
PowerMockito.when(ImmunizationLibrary.getInstance().vaccineRepository().findByEntityId(ArgumentMatchers.anyString())).thenReturn(null);
PowerMockito.when(ImmunizationLibrary.getInstance().context().alertService()).thenReturn(alertService);
PowerMockito.when(ImmunizationLibrary.getInstance().getProperties()).thenReturn(appProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.commonregistry.CommonPersonObjectClient;
Expand Down Expand Up @@ -65,7 +65,7 @@ public class ImmunizationRowAdapterTest extends BaseUnitTest {
@Before
public void setUp() {
org.mockito.MockitoAnnotations.initMocks(this);
view = new ImmunizationRowGroup(RuntimeEnvironment.application, false);
view = new ImmunizationRowGroup(ApplicationProvider.getApplicationContext(), false);
setDataForTest(magicDate);
}

Expand Down Expand Up @@ -148,7 +148,7 @@ public void assertGetCountTestReturnsCount() throws Exception {

@Test
public void assertGetViewReturnsVaccineGroup() {
ImmunizationRowAdapter immunizationRowAdapter = new ImmunizationRowAdapter(RuntimeEnvironment.application, view,
ImmunizationRowAdapter immunizationRowAdapter = new ImmunizationRowAdapter(ApplicationProvider.getApplicationContext(), view,
true, vaccinelist, alertlist);

Assert.assertNotNull(immunizationRowAdapter.getView(0, null, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import android.view.View;
import android.view.ViewGroup;

import junit.framework.Assert;
import org.junit.Assert;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.reflect.Whitebox;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.robolectric.annotation.Config;
import org.smartregister.commonregistry.CommonPersonObjectClient;
import org.smartregister.domain.Alert;
Expand Down Expand Up @@ -71,9 +71,9 @@ public static List<String> getServiceTypeKeys(HashMap<String, List<ServiceType>>

@Before
public void setUp() {
view = new ServiceGroup(RuntimeEnvironment.application);
view = new ServiceGroup(ApplicationProvider.getApplicationContext());
setDataForTest(magicDate);
serviceCardAdapter = new ServiceCardAdapter(RuntimeEnvironment.application, view, serviceTypeList, serviceRecordList,
serviceCardAdapter = new ServiceCardAdapter(ApplicationProvider.getApplicationContext(), view, serviceTypeList, serviceRecordList,
alertList);
org.mockito.MockitoAnnotations.initMocks(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import android.view.View;
import android.view.ViewGroup;

import junit.framework.Assert;
import org.junit.Assert;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.robolectric.annotation.Config;
import org.smartregister.commonregistry.CommonPersonObjectClient;
import org.smartregister.domain.Alert;
Expand Down Expand Up @@ -56,9 +56,9 @@ public class ServiceRowAdapterTest extends BaseUnitTest {

@Before
public void setUp() throws Exception {
view = new ServiceRowGroup(RuntimeEnvironment.application, true);
view = new ServiceRowGroup(ApplicationProvider.getApplicationContext(), true);
setDataForTest(magicDate);
serviceRowAdapter = new ServiceRowAdapter(RuntimeEnvironment.application, view, true, serviceTypeList,
serviceRowAdapter = new ServiceRowAdapter(ApplicationProvider.getApplicationContext(), view, true, serviceTypeList,
serviceRecordList, alertList);
org.mockito.MockitoAnnotations.initMocks(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.reflect.Whitebox;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.robolectric.annotation.Config;
import org.smartregister.commonregistry.CommonPersonObjectClient;
import org.smartregister.domain.Alert;
Expand Down Expand Up @@ -70,9 +70,9 @@ public class VaccineCardAdapterTest extends BaseUnitTest {

@Before
public void setUp() {
view = new VaccineGroup(RuntimeEnvironment.application);
view = new VaccineGroup(ApplicationProvider.getApplicationContext());
setDataForTest(magicDate);
vaccineCardAdapter = new VaccineCardAdapter(RuntimeEnvironment.application, view, "child", vaccineList, alertList);
vaccineCardAdapter = new VaccineCardAdapter(ApplicationProvider.getApplicationContext(), view, "child", vaccineList, alertList);
org.mockito.MockitoAnnotations.initMocks(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.smartregister.immunization.BaseUnitTest;
import org.smartregister.immunization.R;

Expand Down Expand Up @@ -65,7 +65,7 @@ public void testSetFilterTouchesWhenObscuredSetsFlagToTrue() {

Mockito.doReturn(activity).when(activateChildStatusDialogFragment).getActivity();

Mockito.doReturn(RuntimeEnvironment.application.getResources().getString(R.string.activate_child_status_dialog_title)).when(activity).getString(R.string.activate_child_status_dialog_title);
Mockito.doReturn(ApplicationProvider.getApplicationContext().getResources().getString(R.string.activate_child_status_dialog_title)).when(activity).getString(R.string.activate_child_status_dialog_title);

Mockito.doReturn(layoutInflater).when(activity).getLayoutInflater();
Mockito.doReturn(view).when(layoutInflater).inflate(R.layout.dialog_fragment_activate_child_status, viewGroup, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.smartregister.CoreLibrary;
Expand Down Expand Up @@ -98,7 +98,7 @@ public void assertThatCallToNewInstanceCreatesAFragment() {
@Test
public void assertOnCreateViewTestSetsUpTheActivity() {
destroyController();
Intent intent = new Intent(RuntimeEnvironment.application, ServiceDialogFragmentTestActivity.class);
Intent intent = new Intent(ApplicationProvider.getApplicationContext(), ServiceDialogFragmentTestActivity.class);
controller = Robolectric.buildActivity(ServiceDialogFragmentTestActivity.class, intent);
activity = controller.get();
controller.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.smartregister.CoreLibrary;
Expand Down Expand Up @@ -106,7 +106,7 @@ public void assertThatCallToNewInstanceCreatesAFragment() {
@Test
public void assertOnCreateViewTestSetsUpTheActivity() throws Exception {
destroyController();
Intent intent = new Intent(RuntimeEnvironment.application, FragmentUtilActivityUsingServiceActionListener.class);
Intent intent = new Intent(ApplicationProvider.getApplicationContext(), FragmentUtilActivityUsingServiceActionListener.class);
controller = Robolectric.buildActivity(FragmentUtilActivityUsingServiceActionListener.class, intent);
activity = controller.get();
controller.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.smartregister.immunization.BaseUnitTest;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void assertThatCallToNewInstanceCreatesAFragment() {
@Test
public void assertOnCreateViewTestSetsUpTheActivity() throws Exception {
destroyController();
Intent intent = new Intent(RuntimeEnvironment.application, UndoServiceDialogFragmentTestActivity.class);
Intent intent = new Intent(ApplicationProvider.getApplicationContext(), UndoServiceDialogFragmentTestActivity.class);
controller = Robolectric.buildActivity(UndoServiceDialogFragmentTestActivity.class, intent);
activity = controller.get();
controller.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.robolectric.android.controller.ActivityController;
import org.smartregister.CoreLibrary;
import org.smartregister.immunization.BaseUnitTest;
Expand Down Expand Up @@ -87,7 +87,7 @@ private void destroyController() {
@Test
public void assertOnCreateViewTestSetsUpTheActivity() {
destroyController();
Intent intent = new Intent(RuntimeEnvironment.application, UndoVaccinationDialogFragmentTestActivity.class);
Intent intent = new Intent(ApplicationProvider.getApplicationContext(), UndoVaccinationDialogFragmentTestActivity.class);
controller = Robolectric.buildActivity(UndoVaccinationDialogFragmentTestActivity.class, intent);
activity = controller.get();
controller.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
Expand Down Expand Up @@ -101,7 +101,7 @@ private void destroyController() {
@Test
public void assertOnCreateViewTestSetsUpTheActivity() {
destroyController();
Intent intent = new Intent(RuntimeEnvironment.application, VaccinationDialogFragmentTestActivity.class);
Intent intent = new Intent(ApplicationProvider.getApplicationContext(), VaccinationDialogFragmentTestActivity.class);
controller = Robolectric.buildActivity(VaccinationDialogFragmentTestActivity.class, intent);
activity = controller.get();
controller.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.google.gson.reflect.TypeToken;

import org.mockito.Mockito;
import org.robolectric.RuntimeEnvironment;
import androidx.test.core.app.ApplicationProvider;
import org.smartregister.immunization.R;
import org.smartregister.immunization.domain.Vaccine;
import org.smartregister.immunization.domain.VaccineData;
Expand Down Expand Up @@ -97,11 +97,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
.spy((LinearLayout) dialogView.findViewById(R.id.vaccination_name_layout));
Mockito.doReturn(vaccinationNameLayout).when(dialogView).findViewById(R.id.vaccination_name_layout);

LinearLayout vaccineName = Mockito.spy(new LinearLayout(RuntimeEnvironment.application));
LinearLayout vaccineName = Mockito.spy(new LinearLayout(ApplicationProvider.getApplicationContext()));
CheckBoxMock checkBox = Mockito.mock(CheckBoxMock.class);
RadioButtonMock radioButton = Mockito
.mock(RadioButtonMock.class);//new RadioButtonMock(RuntimeEnvironment.application);
TextView textView = new TextView(RuntimeEnvironment.application);
.mock(RadioButtonMock.class);//new RadioButtonMock(ApplicationProvider.getApplicationContext());
TextView textView = new TextView(ApplicationProvider.getApplicationContext());
Mockito.doReturn(vaccineName).when(this.inflater).inflate(R.layout.vaccination_name, null);
Mockito.doReturn(radioButton).when(vaccineName).findViewById(R.id.radio);
Mockito.doReturn(textView).when(vaccineName).findViewById(R.id.vaccine);
Expand Down
Loading

0 comments on commit bd33eeb

Please sign in to comment.