Add impl for force stop action
Also refactor the AnomalyAction so it could take source id as a parameter, which represents the fragment that invokes it. Bug: 36924669 Test: RunSettingsRoboTests Change-Id: Ib53865f92e1a6f1e9dcc1480c0c74fbcfb0226f4
This commit is contained in:
@@ -57,7 +57,7 @@ public class AnomalyDialogFragmentTest {
|
||||
.setPackageName(PACKAGE_NAME)
|
||||
.build();
|
||||
|
||||
mAnomalyDialogFragment = AnomalyDialogFragment.newInstance(mAnomaly);
|
||||
mAnomalyDialogFragment = AnomalyDialogFragment.newInstance(mAnomaly, 0 /* metricskey */);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -84,7 +84,7 @@ public class AnomalySummaryPreferenceControllerTest {
|
||||
mAnomalyList = new ArrayList<>();
|
||||
|
||||
mAnomalySummaryPreferenceController = new AnomalySummaryPreferenceController(
|
||||
mSettingsActivity, mFragment);
|
||||
mSettingsActivity, mFragment, 0 /* metricskey */);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -22,17 +22,25 @@ import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.fuelgauge.anomaly.action.ForceStopAction;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AnomalyUtilsTest {
|
||||
private AnomalyUtils mAnomalyUtils;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mAnomalyUtils = new AnomalyUtils(RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAnomalyAction_typeWakeLock_returnForceStop() {
|
||||
assertThat(AnomalyUtils.getAnomalyAction(Anomaly.AnomalyType.WAKE_LOCK)).isInstanceOf(
|
||||
assertThat(mAnomalyUtils.getAnomalyAction(Anomaly.AnomalyType.WAKE_LOCK)).isInstanceOf(
|
||||
ForceStopAction.class);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.fuelgauge.anomaly.action;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ForceStopActionTest {
|
||||
private static final String PACKAGE_NAME = "com.android.app";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ActivityManager mActivityManager;
|
||||
private ForceStopAction mForceStopAction;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
doReturn(mActivityManager).when(mContext).getSystemService(Context.ACTIVITY_SERVICE);
|
||||
|
||||
mForceStopAction = new ForceStopAction(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePositiveAction_forceStopPackage() {
|
||||
mForceStopAction.handlePositiveAction(PACKAGE_NAME, 0 /* metricskey */);
|
||||
|
||||
verify(mActivityManager).forceStopPackage(PACKAGE_NAME);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user