OSDN Git Service

Add tests for NonIndexableKeys in NFC payments
authorMatthew Fritze <mfritze@google.com>
Thu, 2 Mar 2017 21:44:51 +0000 (13:44 -0800)
committerMatthew Fritze <mfritze@google.com>
Sat, 4 Mar 2017 02:23:28 +0000 (18:23 -0800)
Also serves as an example for testing NIKs.

Test: make RunSettingsRoboTests
Fixes: 3593160635657617

Change-Id: Ia4de8ec3c508ceaa6573252ecd372b479b5ce815

tests/robotests/src/com/android/settings/nfc/PaymentSettingsTest.java [new file with mode: 0644]

diff --git a/tests/robotests/src/com/android/settings/nfc/PaymentSettingsTest.java b/tests/robotests/src/com/android/settings/nfc/PaymentSettingsTest.java
new file mode 100644 (file)
index 0000000..7e898fb
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.android.settings.nfc;
+
+import android.content.Context;
+
+import android.content.pm.PackageManager;
+import android.content.pm.PackageParser;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import java.util.List;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class PaymentSettingsTest {
+    @Mock
+    Context mContext;
+
+    @Mock
+    private PackageManager mManager;
+
+    private PaymentSettings mFragment;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mFragment = new PaymentSettings();
+        when(mContext.getPackageManager()).thenReturn(mManager);
+    }
+
+    @Test
+    public void testNonIndexableKey_NoNFC_KeyAdded() {
+        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
+
+        List<String> niks = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
+        assertThat(niks).contains(mFragment.PAYMENT_KEY);
+    }
+
+    @Test
+    public void testNonIndexableKey_NFC_NoKeyAdded() {
+        when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
+
+        List<String> niks = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
+        assertThat(niks).isNull();
+    }
+}
\ No newline at end of file