Merge "Fix crash in settings robo test."
This commit is contained in:
@@ -27,12 +27,15 @@ import static org.robolectric.Shadows.shadowOf;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.pm.permission.RuntimePermissionPresenter;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.fuelgauge.anomaly.action.AnomalyAction;
|
import com.android.settings.fuelgauge.anomaly.action.AnomalyAction;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowRuntimePermissionPresenter;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -46,7 +49,8 @@ import org.robolectric.shadows.ShadowDialog;
|
|||||||
import org.robolectric.util.FragmentTestUtil;
|
import org.robolectric.util.FragmentTestUtil;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||||
|
shadows = ShadowRuntimePermissionPresenter.class)
|
||||||
public class AnomalyDialogFragmentTest {
|
public class AnomalyDialogFragmentTest {
|
||||||
private static final String PACKAGE_NAME = "com.android.app";
|
private static final String PACKAGE_NAME = "com.android.app";
|
||||||
private static final String DISPLAY_NAME = "app";
|
private static final String DISPLAY_NAME = "app";
|
||||||
@@ -56,6 +60,8 @@ public class AnomalyDialogFragmentTest {
|
|||||||
private AnomalyUtils mAnomalyUtils;
|
private AnomalyUtils mAnomalyUtils;
|
||||||
@Mock
|
@Mock
|
||||||
private AnomalyAction mAnomalyAction;
|
private AnomalyAction mAnomalyAction;
|
||||||
|
@Mock
|
||||||
|
private RuntimePermissionPresenter mRuntimePermissionPresenter;
|
||||||
private Anomaly mWakeLockAnomaly;
|
private Anomaly mWakeLockAnomaly;
|
||||||
private Anomaly mWakeupAlarmAnomaly;
|
private Anomaly mWakeupAlarmAnomaly;
|
||||||
private Anomaly mWakeupAlarmAnomaly2;
|
private Anomaly mWakeupAlarmAnomaly2;
|
||||||
@@ -67,7 +73,7 @@ public class AnomalyDialogFragmentTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mWakeLockAnomaly = new Anomaly.Builder()
|
mWakeLockAnomaly = new Anomaly.Builder()
|
||||||
.setType(Anomaly.AnomalyType.WAKE_LOCK)
|
.setType(Anomaly.AnomalyType.WAKE_LOCK)
|
||||||
.setUid(UID)
|
.setUid(UID)
|
||||||
@@ -93,6 +99,8 @@ public class AnomalyDialogFragmentTest {
|
|||||||
.setPackageName(PACKAGE_NAME)
|
.setPackageName(PACKAGE_NAME)
|
||||||
.setDisplayName(DISPLAY_NAME)
|
.setDisplayName(DISPLAY_NAME)
|
||||||
.build();
|
.build();
|
||||||
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
|
ShadowRuntimePermissionPresenter.setRuntimePermissionPresenter(mRuntimePermissionPresenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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.testutils.shadow;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.permission.RuntimePermissionPresenter;
|
||||||
|
|
||||||
|
|
||||||
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
|
||||||
|
@Implements(RuntimePermissionPresenter.class)
|
||||||
|
public class ShadowRuntimePermissionPresenter {
|
||||||
|
private static RuntimePermissionPresenter mRuntimePermissionPresenter;
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public static RuntimePermissionPresenter getInstance(Context context) {
|
||||||
|
return mRuntimePermissionPresenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setRuntimePermissionPresenter(
|
||||||
|
RuntimePermissionPresenter runtimePermissionPresenter) {
|
||||||
|
mRuntimePermissionPresenter = runtimePermissionPresenter;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user