AdvancedConnectedDeviceDashboardFragmentTest.java revision 687964cf28591b30895a087f6cd364b3a6a9c1b3
1/* 2 * Copyright (C) 2017 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 */ 16package com.android.settings.connecteddevice; 17 18import static com.google.common.truth.Truth.assertThat; 19 20import android.content.Context; 21import android.provider.SearchIndexableResource; 22 23import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController; 24import com.android.settings.testutils.SettingsRobolectricTestRunner; 25import com.android.settings.testutils.XmlTestUtils; 26import com.android.settings.testutils.shadow.ShadowBluetoothPan; 27import com.android.settings.testutils.shadow.ShadowConnectivityManager; 28import com.android.settings.testutils.shadow.ShadowUserManager; 29import com.android.settingslib.drawer.CategoryKey; 30 31import org.junit.Before; 32import org.junit.Test; 33import org.junit.runner.RunWith; 34import org.mockito.MockitoAnnotations; 35import org.robolectric.RuntimeEnvironment; 36import org.robolectric.annotation.Config; 37 38import java.util.List; 39 40@RunWith(SettingsRobolectricTestRunner.class) 41@Config(shadows = {ShadowBluetoothPan.class, ShadowUserManager.class, 42 ShadowConnectivityManager.class}) 43public class AdvancedConnectedDeviceDashboardFragmentTest { 44 45 private AdvancedConnectedDeviceDashboardFragment mFragment; 46 47 @Before 48 public void setUp() { 49 MockitoAnnotations.initMocks(this); 50 51 mFragment = new AdvancedConnectedDeviceDashboardFragment(); 52 } 53 54 @Test 55 public void testCategory_isConnectedDevice() { 56 assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE); 57 } 58 59 @Test 60 public void testSearchIndexProvider_shouldIndexResource() { 61 final List<SearchIndexableResource> indexRes = 62 AdvancedConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER 63 .getXmlResourcesToIndex(RuntimeEnvironment.application, true /* enabled */); 64 65 assertThat(indexRes).isNotNull(); 66 assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId()); 67 } 68 69 @Test 70 public void testGetCategoryKey_returnCategoryDevice() { 71 assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE); 72 } 73 74 @Test 75 public void testNonIndexableKeys_existInXmlLayout() { 76 final Context context = RuntimeEnvironment.application; 77 final List<String> niks = 78 AdvancedConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER 79 .getNonIndexableKeys(context); 80 81 assertThat(niks).contains(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH); 82 } 83} 84