Merge "Deprecate AppListPreference and AppListPrefWithSettings"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f8ecb13168
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.IContentProvider;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -26,6 +25,7 @@ import android.provider.Settings;
|
||||
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.drawer.TileUtils;
|
||||
@@ -40,7 +40,6 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -67,24 +66,6 @@ public class SecuritySettingsTest {
|
||||
|
||||
private SecuritySettings.SummaryProvider mSummaryProvider;
|
||||
|
||||
@Implements(Settings.Secure.class)
|
||||
public static class ShadowSecureSettings {
|
||||
|
||||
private static final Map<String, Object> mValueMap = new HashMap<>();
|
||||
|
||||
@Implementation
|
||||
public static boolean putInt(ContentResolver resolver, String name, int value) {
|
||||
mValueMap.put(name, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int getInt(ContentResolver resolver, String name, int defaultValue) {
|
||||
Integer value = (Integer) mValueMap.get(name);
|
||||
return value == null ? defaultValue : value;
|
||||
}
|
||||
}
|
||||
|
||||
@Implements(com.android.settingslib.drawer.TileUtils.class)
|
||||
public static class ShadowTileUtils {
|
||||
@Implementation
|
||||
|
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.applications.assist;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AssistContextPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private TwoStatePreference mPreference;
|
||||
@Mock
|
||||
private AssistContextPreferenceController.SettingObserver mObserver;
|
||||
private Context mContext;
|
||||
private AssistContextPreferenceController mController;
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
mLifecycle = new Lifecycle();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new AssistContextPreferenceController(mContext, mLifecycle);
|
||||
ReflectionHelpers.setField(mController, "mSettingObserver", mObserver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasAssistant_shouldReturnTrue() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT, "com.android.settings/assist");
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasNoAssistant_shouldReturnFalse() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT, "");
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldUpdatePreference() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT, "com.android.settings/assist");
|
||||
mController.displayPreference(mScreen);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSIST_STRUCTURE_ENABLED, 1);
|
||||
|
||||
mLifecycle.onResume();
|
||||
verify(mObserver).register(any(ContentResolver.class), eq(true));
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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.applications.assist;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
|
||||
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.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AssistFlashScreenPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mMockContext;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private TwoStatePreference mPreference;
|
||||
@Mock
|
||||
private AssistFlashScreenPreferenceController.SettingObserver mObserver;
|
||||
private Context mContext;
|
||||
private AssistFlashScreenPreferenceController mController;
|
||||
private Lifecycle mLifecycle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
mLifecycle = new Lifecycle();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new AssistFlashScreenPreferenceController(mContext, mLifecycle));
|
||||
mLifecycle.addObserver(mController);
|
||||
ReflectionHelpers.setField(mController, "mSettingObserver", mObserver);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowSecureSettings.class})
|
||||
public void isAvailable_hasAssistantAndAllowDisclosure_shouldReturnTrue() {
|
||||
ReflectionHelpers.setField(mController, "mContext", mMockContext);
|
||||
ShadowSecureSettings.putString(null, Settings.Secure.ASSISTANT,
|
||||
"com.android.settings/assist");
|
||||
doReturn(true).when(mController).allowDisablingAssistDisclosure();
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowSecureSettings.class})
|
||||
public void isAvailable_hasAssistantAndDisallowDisclosure_shouldReturnTrue() {
|
||||
ReflectionHelpers.setField(mController, "mContext", mMockContext);
|
||||
ShadowSecureSettings.putString(null, Settings.Secure.ASSISTANT,
|
||||
"com.android.settings/assist");
|
||||
doReturn(false).when(mController).allowDisablingAssistDisclosure();
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasNoAssistant_shouldReturnFalse() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT, "");
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowSecureSettings.class})
|
||||
public void onResume_shouldUpdatePreference() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT, "com.android.settings/assist");
|
||||
doReturn(true).when(mController).isAvailable();
|
||||
doReturn(true).when(mController).isPreInstalledAssistant(any(ComponentName.class));
|
||||
doReturn(true).when(mController).willShowFlash(any(ComponentName.class));
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSIST_DISCLOSURE_ENABLED, 1);
|
||||
|
||||
mLifecycle.onResume();
|
||||
|
||||
verify(mObserver).register(any(ContentResolver.class), eq(true));
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.applications.assist;
|
||||
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DefaultAssistPickerTest {
|
||||
|
||||
private static final ComponentName TEST_ASSIST =
|
||||
new ComponentName("com.android.settings", "assist");
|
||||
|
||||
private Context mContext;
|
||||
private DefaultAssistPicker mPicker;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPicker = spy(new DefaultAssistPicker());
|
||||
mPicker.onAttach(mContext);
|
||||
doReturn(mContext).when(mPicker).getContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultAppKey_shouldUpdateDefaultAssist() {
|
||||
final List<DefaultAssistPicker.Info> assistants = new ArrayList<>();
|
||||
assistants.add(new DefaultAssistPicker.Info(TEST_ASSIST));
|
||||
ReflectionHelpers.setField(mPicker, "mAvailableAssistants", assistants);
|
||||
mPicker.setDefaultAppKey(TEST_ASSIST.flattenToString());
|
||||
|
||||
assertThat(Settings.Secure.getString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT))
|
||||
.isEqualTo(TEST_ASSIST.flattenToString());
|
||||
assertThat(mPicker.getDefaultAppKey())
|
||||
.isEqualTo(TEST_ASSIST.flattenToString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultAppKey_noAvaialbleAssit_shouldClearDefaultAssist() {
|
||||
final List<DefaultAssistPicker.Info> assistants = new ArrayList<>();
|
||||
ReflectionHelpers.setField(mPicker, "mAvailableAssistants", assistants);
|
||||
mPicker.setDefaultAppKey(TEST_ASSIST.flattenToString());
|
||||
|
||||
assertThat(Settings.Secure.getString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT))
|
||||
.isEmpty();
|
||||
assertThat(mPicker.getDefaultAppKey())
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDefaultAppKeyToNull_shouldClearDefaultAssist() {
|
||||
final List<DefaultAssistPicker.Info> assistants = new ArrayList<>();
|
||||
assistants.add(new DefaultAssistPicker.Info(TEST_ASSIST));
|
||||
ReflectionHelpers.setField(mPicker, "mAvailableAssistants", assistants);
|
||||
mPicker.setDefaultAppKey(null);
|
||||
|
||||
assertThat(Settings.Secure.getString(mContext.getContentResolver(),
|
||||
Settings.Secure.ASSISTANT))
|
||||
.isEmpty();
|
||||
assertThat(mPicker.getDefaultAppKey())
|
||||
.isNull();
|
||||
}
|
||||
}
|
@@ -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.applications.assist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.defaultapps.DefaultAppInfo;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DefaultAssistPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
private DefaultAssistPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new DefaultAssistPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAlwaysAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowSecureSettings.class})
|
||||
public void getDefaultAppInfo_hasDefaultAssist_shouldReturnKey() {
|
||||
final String flattenKey = "com.android.settings/assist";
|
||||
ShadowSecureSettings.putString(null, Settings.Secure.ASSISTANT, flattenKey);
|
||||
DefaultAppInfo appInfo = mController.getDefaultAppInfo();
|
||||
|
||||
assertThat(appInfo.getKey()).isEqualTo(flattenKey);
|
||||
}
|
||||
}
|
@@ -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.applications.assist;
|
||||
|
||||
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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class GestureAssistPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private GestureAssistPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new GestureAssistPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldReturnFeatureProviderValue() {
|
||||
when(mFeatureFactory.assistGestureFeatureProvider.isSupported(any(Context.class)))
|
||||
.thenReturn(true);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
|
||||
when(mFeatureFactory.assistGestureFeatureProvider.isSupported(any(Context.class)))
|
||||
.thenReturn(false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.applications.assist;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ManageAssistTest {
|
||||
|
||||
private ManageAssist mSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mSettings = new ManageAssist();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMetricsCategory() {
|
||||
assertThat(mSettings.getMetricsCategory())
|
||||
.isEqualTo(MetricsProto.MetricsEvent.APPLICATIONS_MANAGE_ASSIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCategoryKey() {
|
||||
assertThat(mSettings.getCategoryKey()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceScreenResId() {
|
||||
assertThat(mSettings.getPreferenceScreenResId())
|
||||
.isEqualTo(R.xml.manage_assist);
|
||||
}
|
||||
|
||||
}
|
@@ -85,7 +85,7 @@ public class DefaultAppInfoTest {
|
||||
public void initInfoWithComponent_shouldLoadInfo() {
|
||||
when(mComponentName.getPackageName()).thenReturn("com.android.settings");
|
||||
|
||||
mInfo = new DefaultAppInfo(0 /* uid */, mComponentName, null /*summary */);
|
||||
mInfo = new DefaultAppInfo(0 /* uid */, mComponentName);
|
||||
mInfo.getKey();
|
||||
|
||||
verify(mComponentName).flattenToString();
|
||||
|
@@ -36,7 +36,7 @@ public class SearchIndexProviderCodeInspector extends CodeInspector {
|
||||
private static final String TAG = "SearchCodeInspector";
|
||||
|
||||
private static final String NOT_IMPLEMENTING_INDEXABLE_ERROR =
|
||||
"SettingsPreferenceFragment should implement Indexable, but these are not:\n";
|
||||
"SettingsPreferenceFragment should implement Indexable, but these do not:\n";
|
||||
private static final String NOT_CONTAINING_PROVIDER_OBJECT_ERROR =
|
||||
"Indexable should have public field " + Index.FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER
|
||||
+ " but these are not:\n";
|
||||
|
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.ContentResolver;
|
||||
import android.provider.Settings;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Implements(Settings.Secure.class)
|
||||
public class ShadowSecureSettings {
|
||||
|
||||
private static final Map<String, Object> mValueMap = new HashMap<>();
|
||||
|
||||
@Implementation
|
||||
public static boolean putInt(ContentResolver resolver, String name, int value) {
|
||||
mValueMap.put(name, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static boolean putString(ContentResolver resolver, String name, String value) {
|
||||
mValueMap.put(name, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static String getString(ContentResolver resolver, String name) {
|
||||
return (String) mValueMap.get(name);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static String getStringForUser(ContentResolver resolver, String name, int userHandle) {
|
||||
return getString(resolver, name);
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int getInt(ContentResolver resolver, String name, int defaultValue) {
|
||||
Integer value = (Integer) mValueMap.get(name);
|
||||
return value == null ? defaultValue : value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user