summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2024-03-27 00:29:13 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-03-27 00:29:13 +0000
commit5626385c46fb5a703b4e34f588a7efc878cb25bf (patch)
tree8ad2290f8f5d28906b18e640c9f22cdee7425c57
parent2a6ee5d89d34b2008adb34002f7609064c576978 (diff)
parent0b74cf69e2f5d355639b9ccf5e688f63079b58e7 (diff)
downloadNfc-5626385c46fb5a703b4e34f588a7efc878cb25bf.tar.gz
Merge "Test : New Test Cases for DeviceConfigFacade" into main
-rw-r--r--tests/unit/src/com/android/nfc/DeviceConfigFacadeTest.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/unit/src/com/android/nfc/DeviceConfigFacadeTest.java b/tests/unit/src/com/android/nfc/DeviceConfigFacadeTest.java
new file mode 100644
index 00000000..551d7d10
--- /dev/null
+++ b/tests/unit/src/com/android/nfc/DeviceConfigFacadeTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2024 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.nfc;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.os.Handler;
+import android.util.Log;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoSession;
+import org.mockito.quality.Strictness;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.dx.mockito.inline.extended.ExtendedMockito;
+
+
+@RunWith(AndroidJUnit4.class)
+public class DeviceConfigFacadeTest {
+
+ private static final String TAG = DeviceConfigFacadeTest.class.getSimpleName();
+ private boolean mNfcSupported;
+ private MockitoSession mStaticMockSession;
+ private DeviceConfigFacade mDeviceConfigFacade;
+
+ @Before
+ public void setUp() throws Exception {
+ mStaticMockSession = ExtendedMockito.mockitoSession()
+ .strictness(Strictness.LENIENT)
+ .startMocking();
+
+ Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ PackageManager pm = context.getPackageManager();
+ if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC_ANY)) {
+ mNfcSupported = false;
+ return;
+ }
+ mNfcSupported = true;
+
+
+ Resources mockResources = mock(Resources.class);
+ when(mockResources.getBoolean(eq(R.bool.enable_antenna_blocked_alert)))
+ .thenReturn(true);
+
+
+ Context mockContext = new ContextWrapper(context) {
+
+ @Override
+ public Resources getResources() {
+ Log.i(TAG, "[Mock] getResources");
+ return mockResources;
+ }
+ };
+
+ Handler handler = mock(Handler.class);
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(
+ () -> mDeviceConfigFacade = new DeviceConfigFacade(mockContext, handler));
+ Assert.assertNotNull(mDeviceConfigFacade);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ mStaticMockSession.finishMocking();
+ }
+
+ @Test
+ public void testIsAntennaBlockedAlertEnabled() {
+ if (!mNfcSupported) return;
+
+ boolean isAlertEnabled = mDeviceConfigFacade.isAntennaBlockedAlertEnabled();
+ Log.d(TAG, "isAlertEnabled -" + isAlertEnabled);
+ Assert.assertTrue(isAlertEnabled);
+ }
+}