Update custom shadow usage of ShadowActivityManager

Test: atest SettingsRoboTests

Bug: 319052511
Change-Id: I15ee6a19d039808aab5089e309a872cf6bc818bc
This commit is contained in:
Fan Wu
2024-01-08 18:20:53 +08:00
parent c1c500ae67
commit 1ce7938afc
9 changed files with 79 additions and 78 deletions

View File

@@ -46,6 +46,7 @@ import android.os.UserHandle;
import androidx.fragment.app.FragmentActivity;
import androidx.loader.app.LoaderManager;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
@@ -53,7 +54,6 @@ import com.android.settings.fuelgauge.batteryusage.BatteryDiffEntry;
import com.android.settings.fuelgauge.batteryusage.BatteryEntry;
import com.android.settings.fuelgauge.batteryusage.ConvertUtils;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowActivityManager;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.PrimarySwitchPreference;
@@ -65,15 +65,16 @@ import com.android.settingslib.widget.LayoutPreference;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.stubbing.Answer;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@@ -83,10 +84,13 @@ import java.util.concurrent.TimeUnit;
@Config(
shadows = {
ShadowEntityHeaderController.class,
ShadowActivityManager.class,
com.android.settings.testutils.shadow.ShadowFragment.class,
})
public class AdvancedPowerUsageDetailTest {
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
private static final String APP_LABEL = "app label";
private static final String SUMMARY = "summary";
private static final String[] PACKAGE_NAME = {"com.android.app"};
@@ -125,9 +129,7 @@ public class AdvancedPowerUsageDetailTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getPackageName()).thenReturn("foo");
mFeatureFactory = FakeFeatureFactory.setupForTest();
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;