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