• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.nfc;
19 
20 import android.content.Context;
21 
22 import android.content.pm.PackageManager;
23 import android.content.pm.PackageParser;
24 import com.android.settings.SettingsRobolectricTestRunner;
25 import com.android.settings.TestConfig;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.Mock;
30 import org.mockito.MockitoAnnotations;
31 import org.robolectric.annotation.Config;
32 
33 import java.util.List;
34 
35 import static com.google.common.truth.Truth.assertThat;
36 import static org.mockito.Mockito.mock;
37 import static org.mockito.Mockito.when;
38 
39 @RunWith(SettingsRobolectricTestRunner.class)
40 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
41 public class PaymentSettingsTest {
42     @Mock
43     Context mContext;
44 
45     @Mock
46     private PackageManager mManager;
47 
48     private PaymentSettings mFragment;
49 
50     @Before
setUp()51     public void setUp() {
52         MockitoAnnotations.initMocks(this);
53         mFragment = new PaymentSettings();
54         when(mContext.getPackageManager()).thenReturn(mManager);
55     }
56 
57     @Test
testNonIndexableKey_NoNFC_KeyAdded()58     public void testNonIndexableKey_NoNFC_KeyAdded() {
59         when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
60 
61         List<String> niks = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
62         assertThat(niks).contains(mFragment.PAYMENT_KEY);
63     }
64 
65     @Test
testNonIndexableKey_NFC_NoKeyAdded()66     public void testNonIndexableKey_NFC_NoKeyAdded() {
67         when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
68 
69         List<String> niks = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
70         assertThat(niks).isNull();
71     }
72 }