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
2022a39c2b93bc66db71238274a7683d329232d124James Lemieuximport static com.google.common.truth.Truth.assertThat;
2122a39c2b93bc66db71238274a7683d329232d124James Lemieuximport static org.mockito.Mockito.when;
2222a39c2b93bc66db71238274a7683d329232d124James Lemieux
235e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport android.content.Context;
245e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport android.content.pm.PackageManager;
2582be5f0c3fa4b9511e1e7e4c4e9c20cf31a8294fFan Zhang
269f1e911759dc6fedaac9fa65afb79f6a93022bf4Andrew Sappersteinimport com.android.settings.testutils.SettingsRobolectricTestRunner;
2782be5f0c3fa4b9511e1e7e4c4e9c20cf31a8294fFan Zhang
285e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.junit.Before;
295e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.junit.Test;
305e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.junit.runner.RunWith;
315e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.mockito.Mock;
325e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport org.mockito.MockitoAnnotations;
335e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
345e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzeimport java.util.List;
355e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
365e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze@RunWith(SettingsRobolectricTestRunner.class)
375e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritzepublic class PaymentSettingsTest {
3822a39c2b93bc66db71238274a7683d329232d124James Lemieux
395e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    @Mock
405e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    Context mContext;
415e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
425e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    @Mock
435e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    private PackageManager mManager;
445e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
455e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    private PaymentSettings mFragment;
465e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
475e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    @Before
485e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    public void setUp() {
495e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        MockitoAnnotations.initMocks(this);
505e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        mFragment = new PaymentSettings();
515e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        when(mContext.getPackageManager()).thenReturn(mManager);
525e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    }
535e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
545e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    @Test
555e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    public void testNonIndexableKey_NoNFC_KeyAdded() {
565e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
575e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
5822a39c2b93bc66db71238274a7683d329232d124James Lemieux        final List<String> niks =
5922a39c2b93bc66db71238274a7683d329232d124James Lemieux            PaymentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
6022a39c2b93bc66db71238274a7683d329232d124James Lemieux        assertThat(niks).contains(PaymentSettings.PAYMENT_KEY);
615e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    }
625e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
635e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    @Test
645e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    public void testNonIndexableKey_NFC_NoKeyAdded() {
655e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
665e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze
6722a39c2b93bc66db71238274a7683d329232d124James Lemieux        final List<String> niks =
6822a39c2b93bc66db71238274a7683d329232d124James Lemieux            PaymentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
6982be5f0c3fa4b9511e1e7e4c4e9c20cf31a8294fFan Zhang        assertThat(niks).isEmpty();
705e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze    }
715e1ab7f974125c731946ceb2790670a46efb4314Matthew Fritze}