diff options
| author | 2024-12-19 14:30:28 +0000 | |
|---|---|---|
| committer | 2024-12-19 18:08:29 +0000 | |
| commit | 14f5085df6ea2e6a9e9bb5b25eaede71d02fe422 (patch) | |
| tree | 86c24ec4a5043fdd52a21499e684d2b21d86f46d | |
| parent | 5f2f051b3a5692986d9b1fcba7f8f1c48da9e5ad (diff) | |
Test: Adding Test Cases to CardemulationTest
Test: atest NfcManagerTest
Bug: 314795235
Change-Id: Id1c8cb5fce69ac06b8bcd959a1082e48b40e4e0f
| -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()); + } } |