diff options
author | rachandana <ravikcpd97@gmail.com> | 2024-04-02 19:32:40 +0000 |
---|---|---|
committer | rachandana <ravikcpd97@gmail.com> | 2024-04-02 19:32:55 +0000 |
commit | 8cd639324b35b104c1246733a563aa1e2bc9ea36 (patch) | |
tree | 5cd0b55066b7228673aeb4647083b9a79a299440 | |
parent | 39ee6d184646d01d39b41ea86918675a09037453 (diff) | |
download | Nfc-8cd639324b35b104c1246733a563aa1e2bc9ea36.tar.gz |
Test : New Test Cases for NfcDiscoveryParametersTest
Bug: 314795235
Test: atest NfcUnitTests
Change-Id: I0eda3b3d63c9e34a28b94bae08e6f1bc8f56b738
-rw-r--r-- | tests/unit/src/com/android/nfc/NfcDiscoveryParametersTest.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/unit/src/com/android/nfc/NfcDiscoveryParametersTest.java b/tests/unit/src/com/android/nfc/NfcDiscoveryParametersTest.java new file mode 100644 index 00000000..0237b908 --- /dev/null +++ b/tests/unit/src/com/android/nfc/NfcDiscoveryParametersTest.java @@ -0,0 +1,82 @@ +/* + * 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 android.content.Context; +import android.content.pm.PackageManager; + +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 NfcDiscoveryParametersTest { + + private static final String TAG = NfcDiscoveryParametersTest.class.getSimpleName(); + private boolean mNfcSupported; + private MockitoSession mStaticMockSession; + private NfcDiscoveryParameters mNfcDiscoveryParameters; + + @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; + mNfcDiscoveryParameters = computeDiscoveryParameters(); + } + + @After + public void tearDown() throws Exception { + mStaticMockSession.finishMocking(); + } + + + private NfcDiscoveryParameters computeDiscoveryParameters() { + // Recompute discovery parameters based on screen state + NfcDiscoveryParameters.Builder paramsBuilder = NfcDiscoveryParameters.newBuilder(); + paramsBuilder.setTechMask(1); + paramsBuilder.setEnableReaderMode(true); + paramsBuilder.setEnableHostRouting(true); + return paramsBuilder.build(); + } + + @Test + public void testGetTechMask() { + if (!mNfcSupported) return; + + int techMask = mNfcDiscoveryParameters.getTechMask(); + Assert.assertEquals(1, techMask); + } + +} |