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 17package com.android.settings.gestures; 18 19import android.content.Context; 20import android.provider.SearchIndexableResource; 21 22import com.android.settings.R; 23import com.android.settings.SettingsRobolectricTestRunner; 24import com.android.settings.TestConfig; 25import com.android.settings.core.PreferenceController; 26 27import org.junit.Before; 28import org.junit.Test; 29import org.junit.runner.RunWith; 30import org.mockito.Mock; 31import org.mockito.MockitoAnnotations; 32import org.robolectric.annotation.Config; 33import org.robolectric.shadows.ShadowApplication; 34 35import java.util.List; 36 37import static com.google.common.truth.Truth.assertThat; 38import static org.mockito.Mockito.when; 39 40@RunWith(SettingsRobolectricTestRunner.class) 41@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 42public class SwipeToNotificationSettingsTest { 43 44 @Mock 45 private Context mContext; 46 private SwipeToNotificationSettings mFragment; 47 48 @Before 49 public void setUp() { 50 MockitoAnnotations.initMocks(this); 51 mFragment = new SwipeToNotificationSettings(); 52 } 53 54 @Test 55 public void testGetPreferenceScreenResId() { 56 assertThat(mFragment.getPreferenceScreenResId()) 57 .isEqualTo(R.xml.swipe_to_notification_settings); 58 } 59 60 @Test 61 public void testGetPreferenceControllers_shouldAllBeCreated() { 62 final List<PreferenceController> controllers = mFragment.getPreferenceControllers(mContext); 63 64 assertThat(controllers.isEmpty()).isFalse(); 65 } 66 67 @Test 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