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 20 import static org.mockito.Mockito.spy; 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.ShadowNfcAdapter; 28 import com.android.settings.testutils.shadow.ShadowUserManager; 29 import com.android.settingslib.drawer.CategoryKey; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.mockito.MockitoAnnotations; 35 import org.robolectric.RobolectricTestRunner; 36 import org.robolectric.RuntimeEnvironment; 37 import org.robolectric.annotation.Config; 38 import org.robolectric.shadow.api.Shadow; 39 40 import java.util.List; 41 42 @RunWith(RobolectricTestRunner.class) 43 @Config(shadows = {ShadowUserManager.class, 44 ShadowConnectivityManager.class, ShadowNfcAdapter.class}) 45 public class AdvancedConnectedDeviceDashboardFragmentTest { 46 47 private AdvancedConnectedDeviceDashboardFragment mFragment; 48 49 private Context mContext; 50 private ShadowNfcAdapter mShadowNfcAdapter; 51 52 @Before setUp()53 public void setUp() { 54 MockitoAnnotations.initMocks(this); 55 56 mContext = spy(RuntimeEnvironment.application); 57 mFragment = new AdvancedConnectedDeviceDashboardFragment(); 58 mShadowNfcAdapter = Shadow.extract(NfcAdapter.getDefaultAdapter(mContext)); 59 } 60 61 @Test testCategory_isConnectedDevice()62 public void testCategory_isConnectedDevice() { 63 assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE); 64 } 65 66 @Test testSearchIndexProvider_shouldIndexResource()67 public void testSearchIndexProvider_shouldIndexResource() { 68 final List<SearchIndexableResource> indexRes = 69 AdvancedConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER 70 .getXmlResourcesToIndex(RuntimeEnvironment.application, true /* enabled */); 71 72 assertThat(indexRes).isNotNull(); 73 assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId()); 74 } 75 76 @Test testGetCategoryKey_returnCategoryDevice()77 public void testGetCategoryKey_returnCategoryDevice() { 78 assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE); 79 } 80 } 81