• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.emergency;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import android.database.Cursor;
21 import android.provider.SearchIndexablesContract;
22 
23 import com.android.emergency.R;
24 
25 import java.util.HashSet;
26 import java.util.Set;
27 
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.robolectric.RobolectricTestRunner;
32 
33 /** Unit tests for {@link EmergencySearchIndexablesProvider}. */
34 @RunWith(RobolectricTestRunner.class)
35 public final class EmergencySearchIndexablesProviderTest {
36     private EmergencySearchIndexablesProvider mProvider;
37 
38     @Before
setUp()39     public void setUp() {
40         mProvider = new EmergencySearchIndexablesProvider();
41     }
42 
43     @Test
testQueryXmlResources()44     public void testQueryXmlResources() {
45         Cursor cursor = mProvider.queryXmlResources(
46                 SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS);
47         assertThat(cursor.getColumnNames()).isEqualTo(
48                 SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS);
49         assertThat(cursor.getCount()).isNotEqualTo(0);
50 
51         Set<Integer> expectedXmlResIds = new HashSet();
52         expectedXmlResIds.add(R.xml.edit_emergency_info);
53         expectedXmlResIds.add(R.xml.edit_medical_info);
54 
55         assertThat(cursor.isBeforeFirst()).isTrue();
56         Set<Integer> xmlResIds = new HashSet();
57         while (cursor.moveToNext()) {
58             xmlResIds.add(cursor.getInt(SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID));
59         }
60         assertThat(xmlResIds).isEqualTo(expectedXmlResIds);
61     }
62 
63     @Test
testQueryRawData()64     public void testQueryRawData() {
65         Cursor cursor = mProvider.queryRawData(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS);
66         assertThat(cursor.getColumnNames()).isEqualTo(
67                 SearchIndexablesContract.INDEXABLES_RAW_COLUMNS);
68         assertThat(cursor.getCount()).isEqualTo(0);
69     }
70 
71     @Test
testQueryNonIndexableKeys()72     public void testQueryNonIndexableKeys() {
73         Cursor cursor = mProvider.queryNonIndexableKeys(
74                 SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS);
75         assertThat(cursor.getColumnNames()).isEqualTo(
76                 SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS);
77         assertThat(cursor.getCount()).isEqualTo(0);
78     }
79 }
80