|
@@ -1,6 +1,8 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt |
2 |
2 |
|
package org.litesoft.GWT.client.localstorage; |
3 |
3 |
|
|
|
4 |
+ |
import java.util.*; |
|
5 |
+ |
|
4 |
6 |
|
import junit.framework.*; |
5 |
7 |
|
|
6 |
8 |
|
import org.litesoft.*; |
|
@@ -22,8 +24,221 @@ |
22 |
24 |
|
junit.textui.TestRunner.run( suite() ); |
23 |
25 |
|
} |
24 |
26 |
|
|
25 |
|
- |
public void test_updateDrillDownSetWhenEntriesVisibleChanges() |
|
27 |
+ |
@Override |
|
28 |
+ |
protected void setUp() |
|
29 |
+ |
throws Exception |
|
30 |
+ |
{ |
|
31 |
+ |
mStorage = new LocalStorageImpl( new Html5LocalStorageTestImpl( 4 ) ); |
|
32 |
+ |
} |
|
33 |
+ |
|
|
34 |
+ |
private LocalStorage mStorage; |
|
35 |
+ |
|
|
36 |
+ |
private List<String> keySet() |
|
37 |
+ |
{ |
|
38 |
+ |
List<String> zList = new ArrayList<String>( mStorage.keySet() ); |
|
39 |
+ |
Collections.sort( zList ); |
|
40 |
+ |
return zList; |
|
41 |
+ |
} |
|
42 |
+ |
|
|
43 |
+ |
private List<Map.Entry<String, String>> entrySet() |
|
44 |
+ |
{ |
|
45 |
+ |
List<Map.Entry<String, String>> zList = new ArrayList<Map.Entry<String, String>>( mStorage.entrySet() ); |
|
46 |
+ |
Collections.sort( zList, new Comparator<Map.Entry<String, String>>() |
|
47 |
+ |
{ |
|
48 |
+ |
@Override |
|
49 |
+ |
public int compare( Map.Entry<String, String> o1, Map.Entry<String, String> o2 ) |
|
50 |
+ |
{ |
|
51 |
+ |
return o1.getKey().compareTo( o2.getKey() ); |
|
52 |
+ |
} |
|
53 |
+ |
} ); |
|
54 |
+ |
return zList; |
|
55 |
+ |
} |
|
56 |
+ |
|
|
57 |
+ |
public void test_StorageOne() |
|
58 |
+ |
throws Exception |
|
59 |
+ |
{ |
|
60 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
61 |
+ |
mStorage.put( "K1", "V1" ); |
|
62 |
+ |
assertEquals( 1, mStorage.size() ); |
|
63 |
+ |
assertEquals( "[K1]", mStorage.keySet().toString() ); |
|
64 |
+ |
assertEquals( "V1", mStorage.get( "K1" ) ); |
|
65 |
+ |
assertEquals( "[K1=V1]", mStorage.entrySet().toString() ); |
|
66 |
+ |
assertEquals( "V1", mStorage.remove( "K1" ) ); |
|
67 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
68 |
+ |
|
|
69 |
+ |
mStorage.put( "K1", "V1" ); |
|
70 |
+ |
assertEquals( 1, mStorage.size() ); |
|
71 |
+ |
assertEquals( "V1", mStorage.get( "K1" ) ); |
|
72 |
+ |
mStorage.put( "K1", "V1B" ); |
|
73 |
+ |
assertEquals( 1, mStorage.size() ); |
|
74 |
+ |
assertEquals( "V1B", mStorage.get( "K1" ) ); |
|
75 |
+ |
mStorage.clear(); |
|
76 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
77 |
+ |
} |
|
78 |
+ |
|
|
79 |
+ |
public void test_StorageMany() |
|
80 |
+ |
throws Exception |
|
81 |
+ |
{ |
|
82 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
83 |
+ |
mStorage.put( "K1", "V1" ); |
|
84 |
+ |
mStorage.put( "K2", "V2" ); |
|
85 |
+ |
mStorage.put( "K3", "V3" ); |
|
86 |
+ |
mStorage.put( "K4", "V4" ); |
|
87 |
+ |
assertEquals( 4, mStorage.size() ); |
|
88 |
+ |
assertEquals( "[K1, K2, K3, K4]", keySet().toString() ); |
|
89 |
+ |
assertEquals( "V1", mStorage.get( "K1" ) ); |
|
90 |
+ |
assertEquals( "[K1=V1, K2=V2, K3=V3, K4=V4]", entrySet().toString() ); |
|
91 |
+ |
assertEquals( "V1", mStorage.remove( "K1" ) ); |
|
92 |
+ |
assertEquals( 3, mStorage.size() ); |
|
93 |
+ |
assertEquals( "[K2=V2, K3=V3, K4=V4]", entrySet().toString() ); |
|
94 |
+ |
assertEquals( "V2", mStorage.put( "K2", null ) ); |
|
95 |
+ |
assertEquals( 2, mStorage.size() ); |
|
96 |
+ |
assertEquals( "[K3=V3, K4=V4]", entrySet().toString() ); |
|
97 |
+ |
mStorage.clear(); |
|
98 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
99 |
+ |
} |
|
100 |
+ |
|
|
101 |
+ |
public void test_StorageTooMany() |
|
102 |
+ |
throws Exception |
|
103 |
+ |
{ |
|
104 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
105 |
+ |
mStorage.put( "K1", "V1" ); |
|
106 |
+ |
mStorage.put( "K2", "V2" ); |
|
107 |
+ |
mStorage.put( "K3", "V3" ); |
|
108 |
+ |
mStorage.put( "K4", "V4" ); |
|
109 |
+ |
assertEquals( 4, mStorage.size() ); |
|
110 |
+ |
assertEquals( "[K1=V1, K2=V2, K3=V3, K4=V4]", entrySet().toString() ); |
|
111 |
+ |
|
|
112 |
+ |
try |
|
113 |
+ |
{ |
|
114 |
+ |
mStorage.put( "K5", "V5" ); |
|
115 |
+ |
fail( "Able to add the 5th entry" ); |
|
116 |
+ |
} |
|
117 |
+ |
catch ( UnsupportedOperationException expected ) |
|
118 |
+ |
{ |
|
119 |
+ |
// expected |
|
120 |
+ |
} |
|
121 |
+ |
assertEquals( 4, mStorage.size() ); |
|
122 |
+ |
assertEquals( "[K1=V1, K2=V2, K3=V3, K4=V4]", entrySet().toString() ); |
|
123 |
+ |
} |
|
124 |
+ |
|
|
125 |
+ |
@SuppressWarnings({"RedundantCast", "SuspiciousMethodCalls"}) |
|
126 |
+ |
public void test_StorageNullOrEmpties() |
|
127 |
+ |
throws Exception |
|
128 |
+ |
{ |
|
129 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
130 |
+ |
try |
|
131 |
+ |
{ |
|
132 |
+ |
mStorage.get( (Object) null ); |
|
133 |
+ |
fail( "Able to get w/ null" ); |
|
134 |
+ |
} |
|
135 |
+ |
catch ( IllegalArgumentException expected ) |
|
136 |
+ |
{ |
|
137 |
+ |
// expected |
|
138 |
+ |
} |
|
139 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
140 |
+ |
try |
|
141 |
+ |
{ |
|
142 |
+ |
mStorage.get( (String) null ); |
|
143 |
+ |
fail( "Able to get w/ null" ); |
|
144 |
+ |
} |
|
145 |
+ |
catch ( IllegalArgumentException expected ) |
|
146 |
+ |
{ |
|
147 |
+ |
// expected |
|
148 |
+ |
} |
|
149 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
150 |
+ |
try |
|
151 |
+ |
{ |
|
152 |
+ |
mStorage.get( "" ); |
|
153 |
+ |
fail( "Able to get w/ empty" ); |
|
154 |
+ |
} |
|
155 |
+ |
catch ( IllegalArgumentException expected ) |
|
156 |
+ |
{ |
|
157 |
+ |
// expected |
|
158 |
+ |
} |
|
159 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
160 |
+ |
try |
|
161 |
+ |
{ |
|
162 |
+ |
mStorage.put( null, "V0" ); |
|
163 |
+ |
fail( "Able to put w/ null" ); |
|
164 |
+ |
} |
|
165 |
+ |
catch ( IllegalArgumentException expected ) |
|
166 |
+ |
{ |
|
167 |
+ |
// expected |
|
168 |
+ |
} |
|
169 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
170 |
+ |
try |
|
171 |
+ |
{ |
|
172 |
+ |
mStorage.put( "", "V0" ); |
|
173 |
+ |
fail( "Able to put w/ empty" ); |
|
174 |
+ |
} |
|
175 |
+ |
catch ( IllegalArgumentException expected ) |
|
176 |
+ |
{ |
|
177 |
+ |
// expected |
|
178 |
+ |
} |
|
179 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
180 |
+ |
try |
|
181 |
+ |
{ |
|
182 |
+ |
mStorage.remove( null ); |
|
183 |
+ |
fail( "Able to remove w/ null" ); |
|
184 |
+ |
} |
|
185 |
+ |
catch ( IllegalArgumentException expected ) |
|
186 |
+ |
{ |
|
187 |
+ |
// expected |
|
188 |
+ |
} |
|
189 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
190 |
+ |
try |
|
191 |
+ |
{ |
|
192 |
+ |
mStorage.remove( "" ); |
|
193 |
+ |
fail( "Able to remove w/ empty" ); |
|
194 |
+ |
} |
|
195 |
+ |
catch ( IllegalArgumentException expected ) |
|
196 |
+ |
{ |
|
197 |
+ |
// expected |
|
198 |
+ |
} |
|
199 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
200 |
+ |
} |
|
201 |
+ |
|
|
202 |
+ |
public void test_StorageTrimmed() |
26 |
203 |
|
throws Exception |
27 |
204 |
|
{ |
|
205 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
206 |
+ |
mStorage.put( " K1 ", "V1" ); |
|
207 |
+ |
assertEquals( 1, mStorage.size() ); |
|
208 |
+ |
assertEquals( "[K1]", mStorage.keySet().toString() ); |
|
209 |
+ |
assertEquals( "V1", mStorage.get( " K1 " ) ); |
|
210 |
+ |
assertEquals( "[K1=V1]", mStorage.entrySet().toString() ); |
|
211 |
+ |
assertEquals( "V1", mStorage.remove( " K1 " ) ); |
|
212 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
213 |
+ |
try |
|
214 |
+ |
{ |
|
215 |
+ |
mStorage.get( " " ); |
|
216 |
+ |
fail( "Able to get w/ empty" ); |
|
217 |
+ |
} |
|
218 |
+ |
catch ( IllegalArgumentException expected ) |
|
219 |
+ |
{ |
|
220 |
+ |
// expected |
|
221 |
+ |
} |
|
222 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
223 |
+ |
try |
|
224 |
+ |
{ |
|
225 |
+ |
mStorage.put( " ", "V0" ); |
|
226 |
+ |
fail( "Able to put w/ empty" ); |
|
227 |
+ |
} |
|
228 |
+ |
catch ( IllegalArgumentException expected ) |
|
229 |
+ |
{ |
|
230 |
+ |
// expected |
|
231 |
+ |
} |
|
232 |
+ |
assertTrue( mStorage.isEmpty() ); |
|
233 |
+ |
try |
|
234 |
+ |
{ |
|
235 |
+ |
mStorage.remove( " " ); |
|
236 |
+ |
fail( "Able to remove w/ empty" ); |
|
237 |
+ |
} |
|
238 |
+ |
catch ( IllegalArgumentException expected ) |
|
239 |
+ |
{ |
|
240 |
+ |
// expected |
|
241 |
+ |
} |
|
242 |
+ |
assertTrue( mStorage.isEmpty() ); |
28 |
243 |
|
} |
29 |
244 |
|
} |