• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.nfc;
17 
18 import static org.junit.Assert.assertArrayEquals;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22 
23 import org.junit.Test;
24 
25 import java.util.List;
26 
27 public class ArrayUtilsTest {
28     @Test
testIsEmptyEmptyArray()29     public void testIsEmptyEmptyArray() {
30         assertTrue(ArrayUtils.isEmpty((int[]) null));
31         assertTrue(ArrayUtils.isEmpty(new int[0]));
32     }
33 
34     @Test
testIsEmptyNonEmptyArray()35     public void testIsEmptyNonEmptyArray() {
36         assertFalse(ArrayUtils.isEmpty(new int[] {1, 2, 3}));
37     }
38 
39     @Test
testIsEmptyByteArrayNonEmptyArray()40     public void testIsEmptyByteArrayNonEmptyArray() {
41         assertFalse(ArrayUtils.isEmpty(new byte[] {1, 2, 3}));
42     }
43 
44     @Test
testIsEmptyByteArrayNullArray()45     public void testIsEmptyByteArrayNullArray() {
46         assertTrue(ArrayUtils.isEmpty((byte[]) null));
47     }
48 
49     @Test
testToPrimitiveSingleElementList()50     public void testToPrimitiveSingleElementList() {
51         List<byte[]> list = List.of(new byte[] {1, 2, 3});
52         byte[] result = ArrayUtils.toPrimitive(list);
53         assertArrayEquals(new byte[] {1, 2, 3}, result);
54     }
55 
56     @Test
testToPrimitiveEmptyList()57     public void testToPrimitiveEmptyList() {
58         List<byte[]> list = List.of();
59         byte[] result = ArrayUtils.toPrimitive(list);
60         assertArrayEquals(new byte[0], result);
61     }
62 
63     @Test
testToIndexOfNotNullArray()64     public void testToIndexOfNotNullArray() {
65         assertEquals(2, ArrayUtils.indexOf(new Integer[] {2, 0, -1, 5, 1}, -1));
66     }
67 
68     @Test
testToIndexOfNullArray()69     public void testToIndexOfNullArray() {
70         assertEquals(-1, ArrayUtils.indexOf(null, 8));
71     }
72 
73     @Test
testToIndexOfValueNotFound()74     public void testToIndexOfValueNotFound() {
75         assertEquals(-1, ArrayUtils.indexOf(new Character[] {'a', 'e', 'i', 'o', 'u'}, 'k'));
76     }
77 }