1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings; 18 19 import static com.google.common.truth.Truth.assertThat; 20 import static org.mockito.Mockito.doReturn; 21 import static org.mockito.Mockito.spy; 22 import static org.mockito.Mockito.verify; 23 import static org.mockito.Mockito.when; 24 25 import android.content.Context; 26 import android.os.Build; 27 import android.os.UserManager; 28 import android.support.v7.preference.PreferenceScreen; 29 30 import com.android.settings.dashboard.SummaryLoader; 31 import com.android.settings.testutils.XmlTestUtils; 32 import com.android.settings.testutils.shadow.ShadowUtils; 33 import com.android.settingslib.DeviceInfoUtils; 34 35 import org.junit.Before; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 import org.mockito.Answers; 39 import org.mockito.Mock; 40 import org.mockito.MockitoAnnotations; 41 import org.robolectric.RuntimeEnvironment; 42 import org.robolectric.annotation.Config; 43 44 import java.util.List; 45 46 @RunWith(SettingsRobolectricTestRunner.class) 47 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 48 public class DeviceInfoSettingsTest { 49 50 @Mock(answer = Answers.RETURNS_DEEP_STUBS) 51 private Context mContext; 52 @Mock 53 private PreferenceScreen mScreen; 54 @Mock 55 private UserManager mUserManager; 56 @Mock 57 private SummaryLoader mSummaryLoader; 58 59 private DeviceInfoSettings mSettings; 60 61 @Before setUp()62 public void setUp() { 63 MockitoAnnotations.initMocks(this); 64 when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager); 65 mSettings = spy(new DeviceInfoSettings()); 66 doReturn(mScreen).when(mSettings).getPreferenceScreen(); 67 } 68 69 @Test getPrefXml_shouldReturnDeviceInfoXml()70 public void getPrefXml_shouldReturnDeviceInfoXml() { 71 assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.device_info_settings); 72 } 73 74 @Test getSummary_shouldReturnDeviceModel()75 public void getSummary_shouldReturnDeviceModel() { 76 final SummaryLoader.SummaryProvider mProvider = DeviceInfoSettings.SUMMARY_PROVIDER_FACTORY 77 .createSummaryProvider(null, mSummaryLoader); 78 79 mProvider.setListening(true); 80 81 verify(mSummaryLoader).setSummary(mProvider, Build.MODEL + DeviceInfoUtils.getMsvSuffix()); 82 } 83 84 @Test 85 @Config(shadows = ShadowUtils.class) testNonIndexableKeys_existInXmlLayout()86 public void testNonIndexableKeys_existInXmlLayout() { 87 final Context context = RuntimeEnvironment.application; 88 final List<String> niks = DeviceInfoSettings.SEARCH_INDEX_DATA_PROVIDER 89 .getNonIndexableKeys(context); 90 final int xmlId = (new DeviceInfoSettings()).getPreferenceScreenResId(); 91 92 final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId); 93 94 assertThat(keys).containsAllIn(niks); 95 } 96 } 97