diff options
| author | 2024-12-19 11:56:32 -0800 | |
|---|---|---|
| committer | 2024-12-19 11:56:32 -0800 | |
| commit | 10277ea0703587368a25736c26f190372c5b1666 (patch) | |
| tree | feee92018eb22cc2c2c8c31ba5c1af9b17db1280 | |
| parent | 85925946a8b26f70cf922a158cdf8f02165d13a7 (diff) | |
| parent | 9e5a9cae1d58b4606a97444328721406c33d7ac1 (diff) | |
Merge "Test: Adding Test Cases to CardemulationTest" into main am: 9e5a9cae1d
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3427123
Change-Id: I3185ea2ed9048efa99ad47b380d215bad8c214a3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | nfc/tests/src/android/nfc/cardemulation/CardemulationTest.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/nfc/tests/src/android/nfc/cardemulation/CardemulationTest.java b/nfc/tests/src/android/nfc/cardemulation/CardemulationTest.java index 6be95adbeba0..a21583542a66 100644 --- a/nfc/tests/src/android/nfc/cardemulation/CardemulationTest.java +++ b/nfc/tests/src/android/nfc/cardemulation/CardemulationTest.java @@ -18,17 +18,25 @@ package android.nfc.cardemulation; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.app.role.RoleManager; import android.content.ComponentName; +import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageManager; +import android.nfc.Constants; import android.nfc.INfcCardEmulation; import android.nfc.NfcAdapter; import android.os.RemoteException; import android.os.UserHandle; +import android.provider.Settings; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -61,6 +69,7 @@ public class CardemulationTest { public void setUp() { mMockitoSession = ExtendedMockito.mockitoSession() .mockStatic(NfcAdapter.class) + .mockStatic(Settings.Secure.class) .strictness(Strictness.LENIENT) .startMocking(); MockitoAnnotations.initMocks(this); @@ -110,4 +119,68 @@ public class CardemulationTest { verify(mINfcCardEmulation).isDefaultServiceForAid(1, componentName, "payment"); } + + @Test + public void testCategoryAllowsForegroundPreference() throws Settings.SettingNotFoundException { + when(mContext.createContextAsUser(any(), anyInt())).thenReturn(mContext); + RoleManager roleManager = mock(RoleManager.class); + when(roleManager.isRoleAvailable(RoleManager.ROLE_WALLET)).thenReturn(false); + when(mContext.getSystemService(RoleManager.class)).thenReturn(roleManager); + ContentResolver contentResolver = mock(ContentResolver.class); + when(mContext.getContentResolver()).thenReturn(contentResolver); + when(Settings.Secure.getInt(contentResolver, Constants + .SETTINGS_SECURE_NFC_PAYMENT_FOREGROUND)).thenReturn(1); + boolean result = mCardEmulation.categoryAllowsForegroundPreference("payment"); + assertThat(result).isTrue(); + } + + @Test + public void testGetSelectionModeForCategory() throws RemoteException { + when(mINfcCardEmulation.isDefaultPaymentRegistered()).thenReturn(true); + int result = mCardEmulation.getSelectionModeForCategory("payment"); + assertThat(result).isEqualTo(0); + } + + @Test + public void testSetShouldDefaultToObserveModeForService() throws RemoteException { + UserHandle userHandle = mock(UserHandle.class); + when(userHandle.getIdentifier()).thenReturn(1); + when(mContext.getUser()).thenReturn(userHandle); + ComponentName componentName = mock(ComponentName.class); + when(mINfcCardEmulation.setShouldDefaultToObserveModeForService(1, componentName, true)) + .thenReturn(true); + boolean result = mCardEmulation + .setShouldDefaultToObserveModeForService(componentName, true); + assertThat(result).isTrue(); + verify(mINfcCardEmulation).setShouldDefaultToObserveModeForService(1, componentName, true); + } + + @Test + public void testRegisterPollingLoopFilterForService()throws RemoteException { + UserHandle userHandle = mock(UserHandle.class); + when(userHandle.getIdentifier()).thenReturn(1); + when(mContext.getUser()).thenReturn(userHandle); + ComponentName componentName = mock(ComponentName.class); + when(mINfcCardEmulation.registerPollingLoopFilterForService(anyInt(), + any(), anyString(), anyBoolean())).thenReturn(true); + boolean result = mCardEmulation.registerPollingLoopFilterForService(componentName, + "A0000000041010", true); + assertThat(result).isTrue(); + verify(mINfcCardEmulation) + .registerPollingLoopFilterForService(anyInt(), any(), anyString(), anyBoolean()); + } + + @Test + public void testRemovePollingLoopFilterForService()throws RemoteException { + UserHandle userHandle = mock(UserHandle.class); + when(userHandle.getIdentifier()).thenReturn(1); + when(mContext.getUser()).thenReturn(userHandle); + ComponentName componentName = mock(ComponentName.class); + when(mINfcCardEmulation.removePollingLoopFilterForService(anyInt(), any(), anyString())) + .thenReturn(true); + boolean result = mCardEmulation + .removePollingLoopFilterForService(componentName, "A0000000041010"); + assertThat(result).isTrue(); + verify(mINfcCardEmulation).removePollingLoopFilterForService(anyInt(), any(), anyString()); + } } |