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