litesoft
@ 950
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.client.localstorage; import org.litesoft.*; import junit.framework.*; import java.util.*; public class LocalStorageTest extends TestCasePlus { public static TestSuite suite() { return new TestSuite( LocalStorageTest.class ); } public LocalStorageTest( String name ) { super( name ); } public static void main( String[] args ) { junit.textui.TestRunner.run( suite() ); } @Override protected void setUp() throws Exception { mStorage = new LocalStorageImpl( new Html5LocalStorageTestImpl( 4 ) ); } private LocalStorage mStorage; private List<String> keySet() { List<String> zList = new ArrayList<String>( mStorage.keySet() ); Collections.sort( zList ); return zList; } private List<Map.Entry<String, String>> entrySet() { List<Map.Entry<String, String>> zList = new ArrayList<Map.Entry<String, String>>( mStorage.entrySet() ); Collections.sort( zList, new Comparator<Map.Entry<String, String>>() { @Override public int compare( Map.Entry<String, String> o1, Map.Entry<String, String> o2 ) { return o1.getKey().compareTo( o2.getKey() ); } } ); return zList; } public void test_StorageOne() throws Exception { assertTrue( mStorage.isEmpty() ); mStorage.put( "K1", "V1" ); assertEquals( 1, mStorage.size() ); assertEquals( "[K1]", mStorage.keySet().toString() ); assertEquals( "V1", mStorage.get( "K1" ) ); assertEquals( "[K1=V1]", mStorage.entrySet().toString() ); assertEquals( "V1", mStorage.remove( "K1" ) ); assertTrue( mStorage.isEmpty() ); mStorage.put( "K1", "V1" ); assertEquals( 1, mStorage.size() ); assertEquals( "V1", mStorage.get( "K1" ) ); mStorage.put( "K1", "V1B" ); assertEquals( 1, mStorage.size() ); assertEquals( "V1B", mStorage.get( "K1" ) ); mStorage.clear(); assertTrue( mStorage.isEmpty() ); } public void test_StorageMany() throws Exception { assertTrue( mStorage.isEmpty() ); mStorage.put( "K1", "V1" ); mStorage.put( "K2", "V2" ); mStorage.put( "K3", "V3" ); mStorage.put( "K4", "V4" ); assertEquals( 4, mStorage.size() ); assertEquals( "[K1, K2, K3, K4]", keySet().toString() ); assertEquals( "V1", mStorage.get( "K1" ) ); assertEquals( "[K1=V1, K2=V2, K3=V3, K4=V4]", entrySet().toString() ); assertEquals( "V1", mStorage.remove( "K1" ) ); assertEquals( 3, mStorage.size() ); assertEquals( "[K2=V2, K3=V3, K4=V4]", entrySet().toString() ); assertEquals( "V2", mStorage.put( "K2", null ) ); assertEquals( 2, mStorage.size() ); assertEquals( "[K3=V3, K4=V4]", entrySet().toString() ); mStorage.clear(); assertTrue( mStorage.isEmpty() ); } public void test_StorageTooMany() throws Exception { assertTrue( mStorage.isEmpty() ); mStorage.put( "K1", "V1" ); mStorage.put( "K2", "V2" ); mStorage.put( "K3", "V3" ); mStorage.put( "K4", "V4" ); assertEquals( 4, mStorage.size() ); assertEquals( "[K1=V1, K2=V2, K3=V3, K4=V4]", entrySet().toString() ); try { mStorage.put( "K5", "V5" ); fail( "Able to add the 5th entry" ); } catch ( UnsupportedOperationException expected ) { // expected } assertEquals( 4, mStorage.size() ); assertEquals( "[K1=V1, K2=V2, K3=V3, K4=V4]", entrySet().toString() ); } @SuppressWarnings({"RedundantCast", "SuspiciousMethodCalls"}) public void test_StorageNullOrEmpties() throws Exception { assertTrue( mStorage.isEmpty() ); try { mStorage.get( (Object) null ); fail( "Able to get w/ null" ); } catch ( IllegalArgumentException expected ) { // expected } assertTrue( mStorage.isEmpty() ); try { mStorage.get( (String) null ); fail( "Able to get w/ null" ); } catch ( IllegalArgumentException expected ) { // expected } assertTrue( mStorage.isEmpty() ); try { mStorage.get( "" ); fail( "Able to get w/ empty" ); } catch ( IllegalArgumentException expected ) { // expected } assertTrue( mStorage.isEmpty() ); try { mStorage.put( null, "V0" ); fail( "Able to put w/ null" ); } catch ( IllegalArgumentException expected ) { // expected } assertTrue( mStorage.isEmpty() ); try { mStorage.put( "", "V0" ); fail( "Able to put w/ empty" ); } catch ( IllegalArgumentException expected ) { // expected } assertTrue( mStorage.isEmpty() ); try { mStorage.remove( null ); fail( "Able to remove w/ null" ); } catch ( IllegalArgumentException expected ) { // expected } assertTrue( mStorage.isEmpty() ); try { mStorage.remove( "" ); fail( "Able to remove w/ empty" ); } catch ( IllegalArgumentException expected ) { // expected } assertTrue( mStorage.isEmpty() ); } public void test_StorageTrimmed() throws Exception { assertTrue( mStorage.isEmpty() ); mStorage.put( " K1 ", "V1" ); assertEquals( 1, mStorage.size() ); assertEquals( "[K1]", mStorage.keySet().toString() ); assertEquals( "V1", mStorage.get( " K1 " ) ); assertEquals( "[K1=V1]", mStorage.entrySet().toString() ); assertEquals( "V1", mStorage.remove( " K1 " ) ); assertTrue( mStorage.isEmpty() ); try { mStorage.get( " " ); fail( "Able to get w/ empty" ); } catch ( IllegalArgumentException expected ) { // expected } assertTrue( mStorage.isEmpty() ); try { mStorage.put( " ", "V0" ); fail( "Able to put w/ empty" ); } catch ( IllegalArgumentException expected ) { // expected } assertTrue( mStorage.isEmpty() ); try { mStorage.remove( " " ); fail( "Able to remove w/ empty" ); } catch ( IllegalArgumentException expected ) { // expected } assertTrue( mStorage.isEmpty() ); } } |
Commits for litesoft/trunk/Java/GWT/Server/tests/org/litesoft/GWT/client/localstorage/LocalStorageTest.java
Revision | Author | Commited | Message |
---|---|---|---|
950 Diff | GeorgeS | Thu 19 Jun, 2014 17:57:04 +0000 | New Lines |
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
765 Diff | GeorgeS | Sat 14 Jul, 2012 15:06:46 +0000 | ! |
758 Diff | GeorgeS | Wed 11 Jul, 2012 03:57:35 +0000 | ! |
475 Diff | GeorgeS | Sat 03 Sep, 2011 13:54:51 +0000 | |
277 Diff | GeorgeS | Mon 13 Jun, 2011 16:55:12 +0000 | |
267 Diff | GeorgeS | Sun 12 Jun, 2011 16:08:15 +0000 | |
264 Diff | GeorgeS | Sat 11 Jun, 2011 20:02:23 +0000 | |
262 | GeorgeS | Sat 11 Jun, 2011 19:21:49 +0000 |