1 package org.apache.commons.jcs3.engine.match;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 import java.util.HashSet;
25 import java.util.Set;
26
27
28 public class KeyMatcherPatternImpllUnitTest
29 extends TestCase
30 {
31
32
33
34 public void testGetMatchingKeysFromArray_AllMatch()
35 {
36
37 final int numToInsertPrefix1 = 10;
38 final Set<String> keyArray = new HashSet<>();
39
40 final String keyprefix1 = "MyPrefixC";
41
42
43 for ( int i = 0; i < numToInsertPrefix1; i++ )
44 {
45 keyArray.add(keyprefix1 + String.valueOf( i ));
46 }
47
48 final KeyMatcherPatternImpl<String> keyMatcher = new KeyMatcherPatternImpl<>();
49
50
51 final Set<String> result1 = keyMatcher.getMatchingKeysFromArray( keyprefix1 + ".", keyArray );
52
53
54 assertEquals( "Wrong number returned 1: " + result1, numToInsertPrefix1, result1.size() );
55 }
56
57
58
59
60 public void testGetMatchingKeysFromArray_AllMatchFirstNull()
61 {
62
63 final int numToInsertPrefix1 = 10;
64 final Set<String> keyArray = new HashSet<>();
65
66 final String keyprefix1 = "MyPrefixC";
67
68
69 for ( int i = 1; i < numToInsertPrefix1 + 1; i++ )
70 {
71 keyArray.add(keyprefix1 + String.valueOf( i ));
72 }
73
74 final KeyMatcherPatternImpl<String> keyMatcher = new KeyMatcherPatternImpl<>();
75
76
77 final Set<String> result1 = keyMatcher.getMatchingKeysFromArray( keyprefix1 + "\\S+", keyArray );
78
79
80 assertEquals( "Wrong number returned 1: " + result1, numToInsertPrefix1, result1.size() );
81 }
82
83
84
85
86 public void testGetMatchingKeysFromArray_TwoTypes()
87 {
88
89 final int numToInsertPrefix1 = 10;
90 final int numToInsertPrefix2 = 50;
91 final Set<String> keyArray = new HashSet<>();
92
93 final String keyprefix1 = "MyPrefixA";
94 final String keyprefix2 = "MyPrefixB";
95
96
97 for ( int i = 0; i < numToInsertPrefix1; i++ )
98 {
99 keyArray.add(keyprefix1 + String.valueOf( i ));
100 }
101
102
103 for ( int i = numToInsertPrefix1; i < numToInsertPrefix2 + numToInsertPrefix1; i++ )
104 {
105 keyArray.add(keyprefix2 + String.valueOf( i ));
106 }
107
108 final KeyMatcherPatternImpl<String> keyMatcher = new KeyMatcherPatternImpl<>();
109
110
111 final Set<String> result1 = keyMatcher.getMatchingKeysFromArray( keyprefix1 + ".+", keyArray );
112 final Set<String> result2 = keyMatcher.getMatchingKeysFromArray( keyprefix2 + ".+", keyArray );
113
114
115 assertEquals( "Wrong number returned 1: " + result1, numToInsertPrefix1, result1.size() );
116 assertEquals( "Wrong number returned 2: " + result2, numToInsertPrefix2, result2.size() );
117 }
118 }