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 18 package com.android.settings.search; 19 20 import android.app.Activity; 21 import android.view.Menu; 22 23 import com.android.settings.TestConfig; 24 import com.android.settings.dashboard.SiteMapManager; 25 import com.android.settings.testutils.SettingsRobolectricTestRunner; 26 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 import org.mockito.Answers; 31 import org.mockito.Mock; 32 import org.mockito.MockitoAnnotations; 33 import org.robolectric.Robolectric; 34 import org.robolectric.annotation.Config; 35 36 import static com.google.common.truth.Truth.assertThat; 37 38 @RunWith(SettingsRobolectricTestRunner.class) 39 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 40 public class SearchFeatureProviderImplTest { 41 private SearchFeatureProviderImpl mProvider; 42 private Activity mActivity; 43 44 @Mock(answer = Answers.RETURNS_DEEP_STUBS) 45 private Menu menu; 46 47 @Before 48 public void setUp() { 49 MockitoAnnotations.initMocks(this); 50 mActivity = Robolectric.buildActivity(Activity.class).create().visible().get(); 51 mProvider = new SearchFeatureProviderImpl(); 52 } 53 54 @Test 55 public void getSiteMapManager_shouldCacheInstance() { 56 final SiteMapManager manager1 = mProvider.getSiteMapManager(); 57 final SiteMapManager manager2 = mProvider.getSiteMapManager(); 58 59 assertThat(manager1).isSameAs(manager2); 60 } 61 62 @Test 63 public void getDatabaseSearchLoader_shouldCleanupQuery() { 64 final String query = " space "; 65 final DatabaseResultLoader loader = mProvider.getDatabaseSearchLoader(mActivity, query); 66 67 assertThat(loader.mQueryText).isEqualTo(query.trim()); 68 } 69 70 @Test 71 public void getInstalledAppSearchLoader_shouldCleanupQuery() { 72 final String query = " space "; 73 final InstalledAppResultLoader loader = 74 mProvider.getInstalledAppSearchLoader(mActivity, query); 75 76 assertThat(loader.mQuery).isEqualTo(query.trim()); 77 } 78 79 } 80