• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.android.settings.connecteddevice.ConnectedDeviceDashboardFragment
19         .KEY_AVAILABLE_DEVICES;
20 import static com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment
21         .KEY_CONNECTED_DEVICES;
22 
23 import static com.google.common.truth.Truth.assertThat;
24 
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.spy;
27 
28 import android.content.Context;
29 import android.content.pm.PackageManager;
30 import android.provider.SearchIndexableResource;
31 
32 import com.android.settings.R;
33 import com.android.settings.testutils.SettingsRobolectricTestRunner;
34 import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
35 import com.android.settings.testutils.shadow.ShadowBluetoothPan;
36 import com.android.settings.testutils.shadow.ShadowConnectivityManager;
37 import com.android.settings.testutils.shadow.ShadowUserManager;
38 
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.mockito.Mock;
43 import org.mockito.MockitoAnnotations;
44 import org.robolectric.RuntimeEnvironment;
45 import org.robolectric.annotation.Config;
46 
47 import java.util.List;
48 
49 @RunWith(SettingsRobolectricTestRunner.class)
50 @Config(shadows = {ShadowBluetoothPan.class, ShadowUserManager.class,
51         ShadowConnectivityManager.class, ShadowBluetoothAdapter.class})
52 public class ConnectedDeviceDashboardFragmentTest {
53     @Mock
54     private PackageManager mPackageManager;
55     private Context mContext;
56 
57     @Before
setUp()58     public void setUp() {
59         MockitoAnnotations.initMocks(this);
60 
61         mContext = spy(RuntimeEnvironment.application);
62         doReturn(mPackageManager).when(mContext).getPackageManager();
63         doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
64     }
65 
66     @Test
testSearchIndexProvider_shouldIndexResource()67     public void testSearchIndexProvider_shouldIndexResource() {
68         final List<SearchIndexableResource> indexRes =
69                 ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
70                         .getXmlResourcesToIndex(mContext, true /* enabled */);
71 
72         assertThat(indexRes).isNotNull();
73         assertThat(indexRes.get(0).xmlResId).isEqualTo(R.xml.connected_devices);
74     }
75 
76     @Test
testNonIndexableKeys_existInXmlLayout()77     public void testNonIndexableKeys_existInXmlLayout() {
78         final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
79                 .getNonIndexableKeys(mContext);
80 
81         assertThat(niks).containsExactly(KEY_CONNECTED_DEVICES, KEY_AVAILABLE_DEVICES);
82     }
83 }
84