KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > util > AbstractWildcardMapTest


1 package org.jacorb.test.notification.util;
2
3 import junit.framework.TestCase;
4
5 import org.jacorb.notification.util.WildcardMap;
6
7 /**
8  * @author Alphonse Bendt
9  */

10 public abstract class AbstractWildcardMapTest extends TestCase
11 {
12     protected WildcardMap objectUnderTest_;
13
14     ////////////////////////////////////////
15

16     public AbstractWildcardMapTest(String JavaDoc name)
17     {
18         super(name);
19     }
20
21     ////////////////////////////////////////
22

23     public void setUp() throws Exception JavaDoc
24     {
25         objectUnderTest_ = newWildcardMap();
26     }
27
28     abstract WildcardMap newWildcardMap();
29
30     public void testToString()
31     {
32         assertNotNull(objectUnderTest_.toString());
33     }
34     
35     public void testBugInsertAfterSplit() throws Exception JavaDoc
36     {
37         objectUnderTest_.put("abcd", "ABCD");
38         objectUnderTest_.put("abef", "ABEF");
39         objectUnderTest_.put("ab", "AB");
40
41         assertEquals("ABCD", (objectUnderTest_.getWithExpansion("abcd"))[0]);
42         assertEquals("AB", (objectUnderTest_.getWithExpansion("ab"))[0]);
43         assertEquals("ABEF", (objectUnderTest_.getWithExpansion("abef"))[0]);
44     }
45
46     public void testRemove() throws Exception JavaDoc
47     {
48         objectUnderTest_.put("hallo", "Hallo");
49         objectUnderTest_.put("hallo2", "Hallo2");
50         objectUnderTest_.put("hallo3", "Hallo3");
51         objectUnderTest_.put("hallo4", "Hallo4");
52
53         Object JavaDoc o = objectUnderTest_.remove("hallo2");
54         assertEquals("Hallo2", o);
55
56         Object JavaDoc[] l = objectUnderTest_.getWithExpansion("hallo2");
57
58         assertEquals(0, l.length);
59     }
60
61     public void testClear() throws Exception JavaDoc
62     {
63         assertEquals(0, objectUnderTest_.getWithExpansion("hallo").length);
64     
65         objectUnderTest_.put("hallo", "Hallo");
66         objectUnderTest_.put("hallo*", "Hallo2");
67         
68         assertEquals(2, objectUnderTest_.getWithExpansion("hallo").length);
69         
70         objectUnderTest_.clear();
71         
72         assertEquals(0, objectUnderTest_.getWithExpansion("hallo").length);
73     }
74     
75     public void testAddStar1() throws Exception JavaDoc
76     {
77         objectUnderTest_.put("ha*o", "default");
78         Object JavaDoc[] _res = objectUnderTest_.getWithExpansion("hallo");
79         assertTrue(_res.length == 1);
80
81         _res = objectUnderTest_.getWithExpansion("hall");
82         assertTrue(_res.length == 0);
83
84         _res = objectUnderTest_.getWithExpansion("hao");
85         assertTrue(_res.length == 1);
86
87         _res = objectUnderTest_.getWithExpansion("hadddddo");
88         assertTrue(_res.length == 1);
89     }
90
91     public void testAddStar2() throws Exception JavaDoc
92     {
93         objectUnderTest_.put("*abc*de", "value");
94         Object JavaDoc[] _res = objectUnderTest_.getWithExpansion("abcde");
95         assertTrue(_res.length == 1);
96
97         _res = objectUnderTest_.getWithExpansion("halloabcde");
98         assertTrue(_res.length == 1);
99
100         _res = objectUnderTest_.getWithExpansion("abcbla bla blade");
101         assertTrue(_res.length == 1);
102
103         _res = objectUnderTest_.getWithExpansion("abcde");
104         assertTrue(_res.length == 1);
105
106         _res = objectUnderTest_.getWithExpansion("ab cde");
107         assertEquals(0, _res.length);
108     }
109
110     public void testAddStar() throws Exception JavaDoc
111     {
112         objectUnderTest_.put("abc*", "value1");
113         objectUnderTest_.put("abcd", "value2");
114
115         Object JavaDoc[] _res = objectUnderTest_.getWithExpansion("abc");
116         assertEquals(1, _res.length);
117         assertEquals("value1", _res[0]);
118
119         _res = objectUnderTest_.getWithExpansion("abcd");
120         assertEquals(2, _res.length);
121         assertTrue("value1".equals(_res[0]) || "value1".equals(_res[1]));
122         assertTrue("value2".equals(_res[0]) || "value2".equals(_res[1]));
123     }
124
125     public void testSplitAfterStar() throws Exception JavaDoc
126     {
127         objectUnderTest_.put("abc*def", "value1");
128         objectUnderTest_.put("abc*ef", "value2");
129         objectUnderTest_.put("abc", "value3");
130
131         Object JavaDoc[] _res = objectUnderTest_.getWithExpansion("abcxyzdef");
132         assertEquals(2, _res.length);
133
134         _res = objectUnderTest_.getWithExpansion("abcxyzef");
135         assertEquals(1, _res.length);
136
137         _res = objectUnderTest_.getWithExpansion("abc");
138         assertEquals(1, _res.length);
139     }
140
141     public void testExactGet() throws Exception JavaDoc
142     {
143         objectUnderTest_.put("name1", "value1");
144         objectUnderTest_.put("name2", "value2");
145         objectUnderTest_.put("nane1", "value3");
146         objectUnderTest_.put("nane2", "value4");
147         objectUnderTest_.put("na*", "value5");
148         objectUnderTest_.put("na*e1", "value6");
149
150         assertEquals("value1", objectUnderTest_.getNoExpansion("name1"));
151         assertEquals("value2", objectUnderTest_.getNoExpansion("name2"));
152         assertEquals("value3", objectUnderTest_.getNoExpansion("nane1"));
153         assertEquals("value4", objectUnderTest_.getNoExpansion("nane2"));
154         assertEquals("value5", objectUnderTest_.getNoExpansion("na*"));
155         assertEquals("value6", objectUnderTest_.getNoExpansion("na*e1"));
156     }
157
158     public void testAdd() throws Exception JavaDoc
159     {
160         objectUnderTest_.put("name", "wert");
161         objectUnderTest_.put("java", "Programming Language");
162
163         Object JavaDoc _old = objectUnderTest_.put("name", "neuer wert");
164
165         assertEquals("wert", _old);
166
167         Object JavaDoc[] o1 = objectUnderTest_.getWithExpansion("name");
168         Object JavaDoc[] o2 = objectUnderTest_.getWithExpansion("java");
169
170         assertEquals(1, o1.length);
171         assertEquals("neuer wert", o1[0]);
172
173         assertEquals(1, o2.length);
174         assertEquals("Programming Language", o2[0]);
175     }
176 }
177
178
Popular Tags