diff options
| author | 2024-12-20 12:10:09 -0800 | |
|---|---|---|
| committer | 2024-12-20 12:10:09 -0800 | |
| commit | c80372e465393e63af2d34ef2134902dbc3c3501 (patch) | |
| tree | dfe645df3ae46c8965f81b38f4cfa25ab7ff2da2 | |
| parent | 2f2f177c376bed4f3ddc01415eeb108a67a0dd62 (diff) | |
| parent | 8f7e3bf9007e80e224acc9b7a6f14b7f5c8237cd (diff) | |
Merge "Test: Adding Test Cases to CardemulationTest" into main am: 8f7e3bf900
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3427991
Change-Id: I753c8e1424b58bf6907804d4b29b2bcd282efa4b
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 | 100 |
1 files changed, 99 insertions, 1 deletions
diff --git a/nfc/tests/src/android/nfc/cardemulation/CardemulationTest.java b/nfc/tests/src/android/nfc/cardemulation/CardemulationTest.java index a21583542a66..48632064621c 100644 --- a/nfc/tests/src/android/nfc/cardemulation/CardemulationTest.java +++ b/nfc/tests/src/android/nfc/cardemulation/CardemulationTest.java @@ -51,6 +51,9 @@ import org.mockito.MockitoAnnotations; import org.mockito.MockitoSession; import org.mockito.quality.Strictness; +import java.util.ArrayList; +import java.util.List; + @RunWith(AndroidJUnit4.class) public class CardemulationTest { @@ -171,7 +174,7 @@ public class CardemulationTest { } @Test - public void testRemovePollingLoopFilterForService()throws RemoteException { + public void testRemovePollingLoopFilterForService() throws RemoteException { UserHandle userHandle = mock(UserHandle.class); when(userHandle.getIdentifier()).thenReturn(1); when(mContext.getUser()).thenReturn(userHandle); @@ -183,4 +186,99 @@ public class CardemulationTest { assertThat(result).isTrue(); verify(mINfcCardEmulation).removePollingLoopFilterForService(anyInt(), any(), anyString()); } + + @Test + public void testRegisterPollingLoopPatternFilterForService() throws RemoteException { + UserHandle userHandle = mock(UserHandle.class); + when(userHandle.getIdentifier()).thenReturn(1); + when(mContext.getUser()).thenReturn(userHandle); + ComponentName componentName = mock(ComponentName.class); + when(mINfcCardEmulation.registerPollingLoopPatternFilterForService(anyInt(), any(), + anyString(), anyBoolean())).thenReturn(true); + boolean result = mCardEmulation.registerPollingLoopPatternFilterForService(componentName, + "A0000000041010", true); + assertThat(result).isTrue(); + verify(mINfcCardEmulation).registerPollingLoopPatternFilterForService(anyInt(), any(), + anyString(), anyBoolean()); + } + + @Test + public void testRemovePollingLoopPatternFilterForService() throws RemoteException { + UserHandle userHandle = mock(UserHandle.class); + when(userHandle.getIdentifier()).thenReturn(1); + when(mContext.getUser()).thenReturn(userHandle); + ComponentName componentName = mock(ComponentName.class); + when(mINfcCardEmulation.removePollingLoopPatternFilterForService(anyInt(), any(), + anyString())).thenReturn(true); + boolean result = mCardEmulation.removePollingLoopPatternFilterForService(componentName, + "A0000000041010"); + assertThat(result).isTrue(); + verify(mINfcCardEmulation).removePollingLoopPatternFilterForService(anyInt(), any(), + anyString()); + } + + @Test + public void testRegisterAidsForService() throws RemoteException { + UserHandle userHandle = mock(UserHandle.class); + when(userHandle.getIdentifier()).thenReturn(1); + when(mContext.getUser()).thenReturn(userHandle); + ComponentName componentName = mock(ComponentName.class); + when(mINfcCardEmulation.registerAidGroupForService(anyInt(), any(), + any())).thenReturn(true); + List<String> aids = new ArrayList<>(); + aids.add("A0000000041010"); + boolean result = mCardEmulation.registerAidsForService(componentName, "payment", + aids); + assertThat(result).isTrue(); + verify(mINfcCardEmulation).registerAidGroupForService(anyInt(), any(), + any()); + } + + @Test + public void testUnsetOffHostForService() throws RemoteException { + UserHandle userHandle = mock(UserHandle.class); + when(userHandle.getIdentifier()).thenReturn(1); + when(mContext.getUser()).thenReturn(userHandle); + ComponentName componentName = mock(ComponentName.class); + when(mINfcCardEmulation.unsetOffHostForService(1, componentName)).thenReturn(true); + boolean result = mCardEmulation.unsetOffHostForService(componentName); + assertThat(result).isTrue(); + verify(mINfcCardEmulation).unsetOffHostForService(1, componentName); + } + + @Test + public void testSetOffHostForService() throws RemoteException { + UserHandle userHandle = mock(UserHandle.class); + when(userHandle.getIdentifier()).thenReturn(1); + when(mContext.getUser()).thenReturn(userHandle); + when(NfcAdapter.getDefaultAdapter(any())).thenReturn(mNfcAdapter); + List<String> elements = new ArrayList<>(); + elements.add("eSE"); + when(mNfcAdapter.getSupportedOffHostSecureElements()).thenReturn(elements); + ComponentName componentName = mock(ComponentName.class); + when(mINfcCardEmulation.setOffHostForService(anyInt(), any(), anyString())) + .thenReturn(true); + boolean result = mCardEmulation.setOffHostForService(componentName, + "eSE"); + assertThat(result).isTrue(); + verify(mINfcCardEmulation).setOffHostForService(anyInt(), any(), anyString()); + } + + @Test + public void testGetAidsForService() throws RemoteException { + UserHandle userHandle = mock(UserHandle.class); + when(userHandle.getIdentifier()).thenReturn(1); + when(mContext.getUser()).thenReturn(userHandle); + ComponentName componentName = mock(ComponentName.class); + List<String> elements = new ArrayList<>(); + elements.add("eSE"); + AidGroup aidGroup = mock(AidGroup.class); + when(aidGroup.getAids()).thenReturn(elements); + when(mINfcCardEmulation.getAidGroupForService(1, componentName, "payment")) + .thenReturn(aidGroup); + List<String> result = mCardEmulation.getAidsForService(componentName, "payment"); + assertThat(result).isNotNull(); + assertThat(result.size()).isGreaterThan(0); + verify(mINfcCardEmulation).getAidGroupForService(1, componentName, "payment"); + } } |