ConnectedDeviceDashboardFragmentTest.java revision 762b4969d9c5efaed9241d66abc4417419ddd0e5
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 */
16package com.android.settings.connecteddevice;
17
18import android.content.Context;
19import android.provider.SearchIndexableResource;
20
21import com.android.settings.SettingsRobolectricTestRunner;
22import com.android.settings.TestConfig;
23import com.android.settings.testutils.FakeFeatureFactory;
24import com.android.settingslib.drawer.CategoryKey;
25
26import org.junit.Before;
27import org.junit.Test;
28import org.junit.runner.RunWith;
29import org.mockito.Answers;
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 ConnectedDeviceDashboardFragmentTest {
43
44    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
45    private Context mContext;
46
47    private ConnectedDeviceDashboardFragment mFragment;
48
49    @Before
50    public void setUp() {
51        MockitoAnnotations.initMocks(this);
52        FakeFeatureFactory.setupForTest(mContext);
53        final FakeFeatureFactory factory =
54                (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
55        when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
56        mFragment = new ConnectedDeviceDashboardFragment();
57    }
58
59    @Test
60    public void testCategory_isConnectedDevice() {
61        assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE);
62    }
63
64    @Test
65    public void testSearchIndexProvider_shouldIndexResource() {
66        final List<SearchIndexableResource> indexRes =
67                ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
68                        ShadowApplication.getInstance().getApplicationContext(),
69                        true /* enabled */);
70
71        assertThat(indexRes).isNotNull();
72        assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
73    }
74}
75