1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.commons.compress.harmony.unpack200;
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23
24 import java.util.List;
25
26 import org.junit.jupiter.api.Test;
27
28 class SegmentConstantPoolArrayCacheTest {
29
30 @Test
31 void testMultipleArrayMultipleHit() {
32 final SegmentConstantPoolArrayCache arrayCache = new SegmentConstantPoolArrayCache();
33 final String[] arrayOne = { "Zero", "Shared", "Two", "Shared", "Shared" };
34 final String[] arrayTwo = { "Shared", "One", "Shared", "Shared", "Shared" };
35
36 List<Integer> listOne = arrayCache.indexesForArrayKey(arrayOne, "Shared");
37 List<Integer> listTwo = arrayCache.indexesForArrayKey(arrayTwo, "Shared");
38
39
40 listOne = arrayCache.indexesForArrayKey(arrayOne, "Two");
41 listTwo = arrayCache.indexesForArrayKey(arrayTwo, "Shared");
42
43 assertEquals(1, listOne.size());
44 assertEquals(2, listOne.get(0).intValue());
45
46
47 listOne = arrayCache.indexesForArrayKey(arrayOne, "Shared");
48 assertEquals(3, listOne.size());
49 assertEquals(1, listOne.get(0).intValue());
50 assertEquals(3, listOne.get(1).intValue());
51 assertEquals(4, listOne.get(2).intValue());
52
53 assertEquals(4, listTwo.size());
54 assertEquals(0, listTwo.get(0).intValue());
55 assertEquals(2, listTwo.get(1).intValue());
56 assertEquals(3, listTwo.get(2).intValue());
57 assertEquals(4, listTwo.get(3).intValue());
58
59 final List<Integer> listThree = arrayCache.indexesForArrayKey(arrayOne, "Not found");
60 assertEquals(0, listThree.size());
61 }
62
63 @Test
64 void testSingleMultipleHitArray() {
65 final SegmentConstantPoolArrayCache arrayCache = new SegmentConstantPoolArrayCache();
66 final String[] array = { "Zero", "OneThreeFour", "Two", "OneThreeFour", "OneThreeFour" };
67 final List<Integer> list = arrayCache.indexesForArrayKey(array, "OneThreeFour");
68 assertEquals(3, list.size());
69 assertEquals(1, list.get(0).intValue());
70 assertEquals(3, list.get(1).intValue());
71 assertEquals(4, list.get(2).intValue());
72 }
73
74 @Test
75 void testSingleSimpleArray() {
76 final SegmentConstantPoolArrayCache arrayCache = new SegmentConstantPoolArrayCache();
77 final String[] array = { "Zero", "One", "Two", "Three", "Four" };
78 final List<Integer> list = arrayCache.indexesForArrayKey(array, "Three");
79 assertEquals(1, list.size());
80 assertEquals(3, list.get(0).intValue());
81 }
82
83 }