1 package net.firstpartners.nounit.ui.test; 2 3 26 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Vector ; 30 31 import junit.framework.Test; 32 import junit.framework.TestCase; 33 import junit.framework.TestSuite; 34 import net.firstpartners.nounit.ui.common.CommandPackage; 35 36 39 public class TestCommandPackage extends TestCase { 40 41 45 public TestCommandPackage(String name) { 46 super(name); 47 } 48 49 53 public static void main(String [] args) { 54 junit.textui.TestRunner.run (suite()); 55 } 56 57 61 public static Test suite() { 62 return new TestSuite(TestCommandPackage.class); 63 } 64 65 70 public void testCommandPackageCreation() 71 throws Exception { 72 73 74 String [] tmpSeparateArray = TestUserData.getCommandLineValues(); 75 76 CommandPackage testCommandPackage = new CommandPackage(tmpSeparateArray); 78 79 80 } 82 83 86 public void testGetKeys() throws Exception { 87 88 CommandPackage newWP = new CommandPackage(); 89 assertTrue(newWP.getStoreNames()!=null); 90 assertTrue(newWP.getStoreNames().hasNext()); 92 newWP.addValue("key1","value1"); 94 newWP.addValue("key2","value2"); 95 newWP.addValue("key3","value3"); 96 97 Iterator myEnum = newWP.getStoreNames(); 98 assertTrue(newWP.getStoreNames()!=null); 99 } 100 101 104 public void testAddHashTable() throws Exception { 105 106 CommandPackage newWP = new CommandPackage(); 107 assertTrue(!newWP.getValuePairs().isEmpty()); 109 HashMap newHash = new HashMap (); 111 newHash.put("key1","value1"); 112 newHash.put("key2","value2"); 113 newHash.put("key3","value3"); 114 newWP.addValues(newHash); 115 116 assertTrue(newWP.getValuePairs()!=null); 117 HashMap outHash = newWP.getValuePairs(); 118 assertTrue(!outHash.isEmpty()); 119 assertTrue(outHash.containsKey("key1")); 120 assertTrue(outHash.containsKey("key2")); 121 assertTrue(outHash.containsKey("key3")); 122 assertTrue(outHash.containsKey("key1")); 123 assertTrue(outHash.containsKey("key2")); 124 assertTrue(outHash.containsKey("key3")); 125 126 } 127 128 131 public void testStoreGetInt() throws Exception { 132 133 CommandPackage newWP = new CommandPackage(); 134 135 newWP.addValue("num1",new Integer (1024)); 136 newWP.addValue("num2","876"); 137 newWP.addValue("letters","xyz"); 138 139 assertTrue(newWP.getInt("num1") == 1024); 140 assertTrue(newWP.getInt("num2") == 876); 141 assertTrue(newWP.getInt("letters") == 0); 142 assertTrue(newWP.getInt("some-randon-non-existant-key") == 0); 143 144 } 145 146 147 150 public void testMultipleValues() throws Exception { 151 152 CommandPackage newWP = new CommandPackage(); 153 154 String [] valuesAdd = {"samekey","value1", 155 "samekey","value2", 156 "samekey","value3"}; 157 158 newWP.addValues(valuesAdd); 159 160 Object tmpObject = newWP.getValue("samekey"); 161 assertTrue(tmpObject!=null); 162 assertTrue(tmpObject instanceof Vector ); 163 164 Vector tmpVector = (Vector ) tmpObject; 166 assertTrue(!tmpVector.isEmpty()); 167 assertTrue(tmpVector.contains("value1")); 168 assertTrue(tmpVector.contains("value2")); 169 assertTrue(tmpVector.contains("value3")); 170 assertTrue(tmpVector.size()==3); 171 172 tmpVector = newWP.getVector("samekey"); 174 assertTrue(!tmpVector.isEmpty()); 175 assertTrue(tmpVector.contains("value1")); 176 assertTrue(tmpVector.contains("value2")); 177 assertTrue(tmpVector.contains("value3")); 178 assertTrue(tmpVector.size()==3); 179 180 } 181 182 186 public void testDoubleAdd() throws Exception { 187 188 CommandPackage myWP = new CommandPackage(); 189 190 myWP.addValue("key1","value1"); 191 192 String [] valuesAdd = {"key1","value1", 194 "key2","value2", 195 "key3","value3"}; 196 197 myWP.addValues(valuesAdd); 199 myWP.addValues(valuesAdd); 200 201 Object tmpObject = myWP.getValue("key1"); 203 assertTrue(tmpObject instanceof String ); 204 205 } 206 207 208 209 212 public void testAddAdditionalData() { 213 214 CommandPackage myWp = new CommandPackage(); 215 myWp.addAdditionalValue("somerandomkeyxxx","someobject"); 216 217 Object tmpObject = myWp.getValue("somerandomkeyxxx"); 218 assertTrue(tmpObject!=null); 219 assertTrue(tmpObject instanceof String ); 220 221 myWp.addAdditionalValue("somerandomkeyxxx","someotherobject"); 223 tmpObject = myWp.getValue("somerandomkeyxxx"); 224 assertTrue(tmpObject!=null); 225 assertTrue(tmpObject instanceof Vector ); 226 227 Vector tmpVector = (Vector )tmpObject; 229 assertTrue(!tmpVector.isEmpty()); 230 assertTrue(tmpVector.contains("someobject")); 231 assertTrue(tmpVector.contains("someotherobject")); 232 233 } 234 235 238 public void testRemove(){ 239 240 CommandPackage myWp= new CommandPackage(); 241 myWp.addValue("X2345","LLL"); 242 assertTrue(myWp.getValue("X2345")!=null); 243 myWp.remove("X2345"); 244 assertTrue(myWp.getValue("X2345")==null); 245 246 } 247 248 251 public void testMove(){ 252 253 CommandPackage myWp= new CommandPackage(); 254 255 myWp.addValue("SomeKey1","SomeValue"); 256 assertTrue(myWp.getValue("SomeKey1")!=null); 257 assertTrue(myWp.getValue("SomeNewKey1")==null); 258 259 myWp.move("SomeKey1","SomeNewKey1"); 260 assertTrue(myWp.getValue("SomeKey1")==null); 261 assertTrue(myWp.getValue("SomeNewKey1")!=null); 262 263 } 264 265 } | Popular Tags |