• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.SettingsRobolectricTestRunner;
24 import com.android.settings.TestConfig;
25 import com.android.settings.dashboard.SiteMapManager;
26 import com.android.settings.search2.SearchFeatureProviderImpl;
27 
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Answers;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.robolectric.Robolectric;
35 import org.robolectric.annotation.Config;
36 
37 
38 import static com.google.common.truth.Truth.assertThat;
39 import static org.mockito.Matchers.anyInt;
40 import static org.mockito.Matchers.anyString;
41 import static org.mockito.Mockito.verify;
42 
43 @RunWith(SettingsRobolectricTestRunner.class)
44 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
45 public class SearchFeatureProviderImplTest {
46     private SearchFeatureProviderImpl mProvider;
47     private Activity mActivity;
48 
49     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
50     private Menu menu;
51 
52     @Before
setUp()53     public void setUp() {
54         MockitoAnnotations.initMocks(this);
55         mActivity = Robolectric.buildActivity(Activity.class).create().visible().get();
56         mProvider = new SearchFeatureProviderImpl();
57     }
58 
59     @Test
testPassNull_NoError()60     public void testPassNull_NoError() {
61         mProvider.setUpSearchMenu(null, null);
62     }
63 
64     @Test
testSetUpMenu_HasItemAdded()65     public void testSetUpMenu_HasItemAdded() {
66         mProvider.setUpSearchMenu(menu, mActivity);
67 
68         verify(menu).add(anyInt(), anyInt(), anyInt(), anyString());
69     }
70 
71     @Test
getSiteMapManager_shouldCacheInstance()72     public void getSiteMapManager_shouldCacheInstance() {
73         final SiteMapManager manager1 = mProvider.getSiteMapManager();
74         final SiteMapManager manager2 = mProvider.getSiteMapManager();
75 
76         assertThat(manager1).isSameAs(manager2);
77     }
78 }
79