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