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