1 26 27 package net.sourceforge.groboutils.uicapture.v1.javamaker; 28 29 import java.io.File ; 30 import java.io.Writer ; 31 import java.io.StringWriter ; 32 import java.io.IOException ; 33 34 import net.sourceforge.groboutils.autodoc.v1.AutoDoc; 35 import junit.framework.Test; 36 import junit.framework.TestCase; 37 import junit.framework.TestSuite; 38 39 40 47 public class JavaMakerIUTest extends TestCase 48 { 49 52 private static final Class THIS_CLASS = JavaMakerIUTest.class; 53 private static final AutoDoc DOC = new AutoDoc( THIS_CLASS ); 54 55 public JavaMakerIUTest( String name ) 56 { 57 super( name ); 58 } 59 60 61 62 65 public void testInstantiation() 66 throws IOException 67 { 68 try 69 { 70 new JavaMaker( (File )null, null, null ); 71 fail( "Should throw IAE" ); 72 } 73 catch (IllegalArgumentException iae) 74 { 75 } 77 try 78 { 79 new JavaMaker( (Writer )null, null, null ); 80 fail( "Should throw IAE" ); 81 } 82 catch (IllegalArgumentException iae) 83 { 84 } 86 File f = new File ("a"); 87 try 88 { 89 new JavaMaker( f, "b", "c" ); 90 } 91 finally 92 { 93 if (f.exists()) 94 { 95 f.delete(); 96 } 97 } 98 } 99 100 101 public void testCreatesFile() 102 throws IOException 103 { 104 File f = File.createTempFile( "Script", ".java" ); 105 try 106 { 107 if (f.exists()) 108 { 109 f.delete(); 110 } 111 assertTrue( 112 "Generated a temporary file. It should not already exist.", 113 !f.exists() ); 114 115 JavaMaker jsm = new JavaMaker( f, "a", "b" ); 116 117 jsm.start(); 118 jsm.end(); 119 120 assertTrue( 121 "ScriptMaker should have created temp file.", 122 f.exists() ); 123 } 124 finally 125 { 126 if (f.exists()) 127 { 128 f.delete(); 129 } 130 } 131 } 132 133 134 public void testCreatesString() 135 { 136 StringWriter sw = new StringWriter (); 137 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 138 139 jsm.start(); 140 jsm.end(); 141 142 String output = sw.toString(); 143 assertTrue( 144 "ScriptMaker should have created a non-empty string.", 145 output.length() > 0 ); 146 } 147 148 149 public void testIllegalOrderEnd() 150 { 151 StringWriter sw = new StringWriter (); 152 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 153 154 try 155 { 156 jsm.end(); 157 fail( "end should have thrown an IllegalStateException." ); 158 } 159 catch (IllegalStateException e) 160 { 161 } 163 } 164 165 166 public void testIllegalOrderDelay() 167 { 168 StringWriter sw = new StringWriter (); 169 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 170 171 try 172 { 173 jsm.generateDelay( 10 ); 174 fail( "generateDelay should have thrown an IllegalStateException." ); 175 } 176 catch (IllegalStateException e) 177 { 178 } 180 } 181 182 183 public void testIllegalOrderWheel() 184 { 185 StringWriter sw = new StringWriter (); 186 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 187 188 try 189 { 190 jsm.generateMoveMouseWheel( 10 ); 191 fail( "generateMoveMouseWheel should have thrown an IllegalStateException." ); 192 } 193 catch (IllegalStateException e) 194 { 195 } 197 } 198 199 200 public void testIllegalOrderMove() 201 { 202 StringWriter sw = new StringWriter (); 203 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 204 205 try 206 { 207 jsm.generateMoveMouse( 10, 10 ); 208 fail( "generateMoveMouse should have thrown an IllegalStateException." ); 209 } 210 catch (IllegalStateException e) 211 { 212 } 214 } 215 216 217 public void testIllegalOrderMPress() 218 { 219 StringWriter sw = new StringWriter (); 220 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 221 222 try 223 { 224 jsm.generatePressMouse( 10 ); 225 fail( "generatePressMouse should have thrown an IllegalStateException." ); 226 } 227 catch (IllegalStateException e) 228 { 229 } 231 } 232 233 234 public void testIllegalOrderMRelease() 235 { 236 StringWriter sw = new StringWriter (); 237 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 238 239 try 240 { 241 jsm.generateReleaseMouse( 10 ); 242 fail( "generateReleaseMouse should have thrown an IllegalStateException." ); 243 } 244 catch (IllegalStateException e) 245 { 246 } 248 } 249 250 251 public void testIllegalOrderKPress() 252 { 253 StringWriter sw = new StringWriter (); 254 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 255 256 try 257 { 258 jsm.generatePressKey( 10 ); 259 fail( "generatePressKey should have thrown an IllegalStateException." ); 260 } 261 catch (IllegalStateException e) 262 { 263 } 265 } 266 267 268 public void testIllegalOrderKRelease() 269 { 270 StringWriter sw = new StringWriter (); 271 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 272 273 try 274 { 275 jsm.generateReleaseKey( 10 ); 276 fail( "generateReleaseKey should have thrown an IllegalStateException." ); 277 } 278 catch (IllegalStateException e) 279 { 280 } 282 } 283 284 285 public void testIllegalOrderScreen() 286 { 287 StringWriter sw = new StringWriter (); 288 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 289 290 try 291 { 292 jsm.generateScreenCapture( null, 10, 10, 10, 10 ); 293 fail( "generateScreenCapture should have thrown an IllegalStateException." ); 294 } 295 catch (IllegalStateException e) 296 { 297 } 299 } 300 301 302 public void testIllegalOrderStart() 303 { 304 StringWriter sw = new StringWriter (); 305 JavaMaker jsm = new JavaMaker( sw, "a", "b" ); 306 307 jsm.start(); 308 try 309 { 310 jsm.start(); 311 fail( "start should have thrown an IllegalStateException." ); 312 } 313 catch (IllegalStateException e) 314 { 315 } 317 finally 318 { 319 jsm.end(); 320 } 321 } 322 323 324 325 326 329 330 public static Test suite() 331 { 332 TestSuite suite = new TestSuite( THIS_CLASS ); 333 334 return suite; 335 } 336 337 public static void main( String [] args ) 338 { 339 String [] name = { THIS_CLASS.getName() }; 340 341 344 junit.textui.TestRunner.main( name ); 345 } 346 347 351 protected void setUp() throws Exception 352 { 353 super.setUp(); 354 355 } 357 358 359 363 protected void tearDown() throws Exception 364 { 365 367 368 super.tearDown(); 369 } 370 } 371 372 | Popular Tags |