1 /* 2 * Copyright (C) 2016 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 17 package com.android.settings.gestures; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.provider.SearchIndexableResource; 23 24 import com.android.settings.R; 25 import com.android.settings.TestConfig; 26 import com.android.settings.testutils.SettingsRobolectricTestRunner; 27 import com.android.settingslib.core.AbstractPreferenceController; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.mockito.Mock; 33 import org.mockito.MockitoAnnotations; 34 import org.robolectric.annotation.Config; 35 import org.robolectric.shadows.ShadowApplication; 36 37 import java.util.List; 38 39 @RunWith(SettingsRobolectricTestRunner.class) 40 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 41 public class SwipeToNotificationSettingsTest { 42 43 @Mock 44 private Context mContext; 45 private SwipeToNotificationSettings mFragment; 46 47 @Before setUp()48 public void setUp() { 49 MockitoAnnotations.initMocks(this); 50 mFragment = new SwipeToNotificationSettings(); 51 } 52 53 @Test testGetPreferenceScreenResId()54 public void testGetPreferenceScreenResId() { 55 assertThat(mFragment.getPreferenceScreenResId()) 56 .isEqualTo(R.xml.swipe_to_notification_settings); 57 } 58 59 @Test testGetPreferenceControllers_shouldAllBeCreated()60 public void testGetPreferenceControllers_shouldAllBeCreated() { 61 final List<AbstractPreferenceController> controllers = 62 mFragment.getPreferenceControllers(mContext); 63 64 assertThat(controllers.isEmpty()).isFalse(); 65 } 66 67 @Test testSearchIndexProvider_shouldIndexResource()68 public void testSearchIndexProvider_shouldIndexResource() { 69 final List<SearchIndexableResource> indexRes = 70 SwipeToNotificationSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( 71 ShadowApplication.getInstance().getApplicationContext(), 72 true /* enabled */); 73 74 assertThat(indexRes).isNotNull(); 75 assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId()); 76 } 77 } 78