15e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze/*
25e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze * Copyright (C) 2017 The Android Open Source Project
35e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze *
45e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze * Licensed under the Apache License, Version 2.0 (the "License");
55e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze * you may not use this file except in compliance with the License.
65e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze * You may obtain a copy of the License at
75e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze *
85e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze *      http://www.apache.org/licenses/LICENSE-2.0
95e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze *
105e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze * Unless required by applicable law or agreed to in writing, software
115e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze * distributed under the License is distributed on an "AS IS" BASIS,
125e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze * See the License for the specific language governing permissions and
145e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze * limitations under the License.
155e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze *
165e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze */
175e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
185e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzepackage com.android.settings.nfc;
195e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
205e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport android.content.Context;
215e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport android.content.pm.PackageManager;
2282be5f0c3fa4b9511e1e7e4c4e9c20cf31a8294fFan Zhang
239f1e911759dc6fedaac9fa65afb79f6a93022bf4Andrew Sappersteinimport com.android.settings.testutils.SettingsRobolectricTestRunner;
245e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport com.android.settings.TestConfig;
2582be5f0c3fa4b9511e1e7e4c4e9c20cf31a8294fFan Zhang
265e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.junit.Before;
275e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.junit.Test;
285e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.junit.runner.RunWith;
295e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.mockito.Mock;
305e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.mockito.MockitoAnnotations;
315e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.robolectric.annotation.Config;
325e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
335e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport java.util.List;
345e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
355e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport static com.google.common.truth.Truth.assertThat;
365e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport static org.mockito.Mockito.when;
375e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
385e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze@RunWith(SettingsRobolectricTestRunner.class)
395e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
405e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzepublic class PaymentSettingsTest {
415e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    @Mock
425e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    Context mContext;
435e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
445e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    @Mock
455e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    private PackageManager mManager;
465e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
475e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    private PaymentSettings mFragment;
485e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
495e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    @Before
505e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    public void setUp() {
515e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        MockitoAnnotations.initMocks(this);
525e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        mFragment = new PaymentSettings();
535e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        when(mContext.getPackageManager()).thenReturn(mManager);
545e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    }
555e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
565e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    @Test
575e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    public void testNonIndexableKey_NoNFC_KeyAdded() {
585e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
595e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
605e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        List<String> niks = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
615e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        assertThat(niks).contains(mFragment.PAYMENT_KEY);
625e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    }
635e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
645e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    @Test
655e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    public void testNonIndexableKey_NFC_NoKeyAdded() {
665e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
675e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
685e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        List<String> niks = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
6982be5f0c3fa4b9511e1e7e4c4e9c20cf31a8294fFan Zhang        assertThat(niks).isEmpty();
705e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    }
715e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze}