summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Bob Wang <ziyiw@google.com> 2024-11-27 21:42:54 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2024-11-27 21:42:54 +0000
commitae98de70e7be26e1b65229c15a038c22b8d5ebba (patch)
tree7dec8b9f1cae61dde827709c52a157834bd445a8
parent97ee8ce02329c769cc5307ad97808cac35ee04e8 (diff)
parent8dc8995148301f349cc284989aff035d97e10a43 (diff)
Merge "Test: Adding Test Cases to NdefRecordTest" into main am: 5341e4b4c4 am: 8dc8995148
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3379788 Change-Id: Ifd10da3d3857367e289dab7cc3d402062a1a8b54 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--nfc/tests/src/android/nfc/NdefRecordTest.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/nfc/tests/src/android/nfc/NdefRecordTest.java b/nfc/tests/src/android/nfc/NdefRecordTest.java
new file mode 100644
index 000000000000..231e939b4fbe
--- /dev/null
+++ b/nfc/tests/src/android/nfc/NdefRecordTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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 android.nfc;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class NdefRecordTest {
+
+ @Test
+ public void testNdefRecordConstructor() throws FormatException {
+ NdefRecord applicationRecord = NdefRecord
+ .createApplicationRecord("com.android.test");
+ NdefRecord ndefRecord = new NdefRecord(applicationRecord.toByteArray());
+ assertThat(ndefRecord).isNotNull();
+ assertThat(ndefRecord.toByteArray().length).isGreaterThan(0);
+ assertThat(ndefRecord.getType()).isEqualTo("android.com:pkg".getBytes());
+ assertThat(ndefRecord.getPayload()).isEqualTo("com.android.test".getBytes());
+ }
+
+ @Test
+ public void testCreateExternal() {
+ NdefRecord ndefRecord = NdefRecord.createExternal("test",
+ "android.com:pkg", "com.android.test".getBytes());
+ assertThat(ndefRecord).isNotNull();
+ assertThat(ndefRecord.getType()).isEqualTo("test:android.com:pkg".getBytes());
+ assertThat(ndefRecord.getPayload()).isEqualTo("com.android.test".getBytes());
+ }
+
+ @Test
+ public void testCreateUri() {
+ NdefRecord ndefRecord = NdefRecord.createUri("http://www.example.com");
+ assertThat(ndefRecord).isNotNull();
+ assertThat(ndefRecord.getTnf()).isEqualTo(NdefRecord.TNF_WELL_KNOWN);
+ assertThat(ndefRecord.getType()).isEqualTo(NdefRecord.RTD_URI);
+ }
+
+}