KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > uicapture > v1 > javamaker > JavaMakerIUTest


1 /*
2  * @(#)JavaMakerIUTest.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.uicapture.v1.javamaker;
28
29 import java.io.File JavaDoc;
30 import java.io.Writer JavaDoc;
31 import java.io.StringWriter JavaDoc;
32 import java.io.IOException JavaDoc;
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 /**
41  * Tests the JavaMaker class.
42  *
43  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
44  * @since Jan 6, 2002
45  * @version $Date: 2003/02/10 22:52:34 $
46  */

47 public class JavaMakerIUTest extends TestCase
48 {
49     //-------------------------------------------------------------------------
50
// Standard JUnit Class-specific declarations
51

52     private static final Class JavaDoc THIS_CLASS = JavaMakerIUTest.class;
53     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
54     
55     public JavaMakerIUTest( String JavaDoc name )
56     {
57         super( name );
58     }
59
60
61
62     //-------------------------------------------------------------------------
63
// Tests
64

65     public void testInstantiation()
66             throws IOException JavaDoc
67     {
68         try
69         {
70             new JavaMaker( (File JavaDoc)null, null, null );
71             fail( "Should throw IAE" );
72         }
73         catch (IllegalArgumentException JavaDoc iae)
74         {
75             // do nothing
76
}
77         try
78         {
79             new JavaMaker( (Writer JavaDoc)null, null, null );
80             fail( "Should throw IAE" );
81         }
82         catch (IllegalArgumentException JavaDoc iae)
83         {
84             // do nothing
85
}
86         File JavaDoc f = new File JavaDoc("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 JavaDoc
103     {
104         File JavaDoc 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 JavaDoc sw = new StringWriter JavaDoc();
137         JavaMaker jsm = new JavaMaker( sw, "a", "b" );
138         
139         jsm.start();
140         jsm.end();
141         
142         String JavaDoc 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 JavaDoc sw = new StringWriter JavaDoc();
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 JavaDoc e)
160         {
161             // should have generated this exception
162
}
163     }
164
165
166     public void testIllegalOrderDelay()
167     {
168         StringWriter JavaDoc sw = new StringWriter JavaDoc();
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 JavaDoc e)
177         {
178             // should have generated this exception
179
}
180     }
181
182
183     public void testIllegalOrderWheel()
184     {
185         StringWriter JavaDoc sw = new StringWriter JavaDoc();
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 JavaDoc e)
194         {
195             // should have generated this exception
196
}
197     }
198
199
200     public void testIllegalOrderMove()
201     {
202         StringWriter JavaDoc sw = new StringWriter JavaDoc();
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 JavaDoc e)
211         {
212             // should have generated this exception
213
}
214     }
215
216
217     public void testIllegalOrderMPress()
218     {
219         StringWriter JavaDoc sw = new StringWriter JavaDoc();
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 JavaDoc e)
228         {
229             // should have generated this exception
230
}
231     }
232
233
234     public void testIllegalOrderMRelease()
235     {
236         StringWriter JavaDoc sw = new StringWriter JavaDoc();
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 JavaDoc e)
245         {
246             // should have generated this exception
247
}
248     }
249
250
251     public void testIllegalOrderKPress()
252     {
253         StringWriter JavaDoc sw = new StringWriter JavaDoc();
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 JavaDoc e)
262         {
263             // should have generated this exception
264
}
265     }
266
267
268     public void testIllegalOrderKRelease()
269     {
270         StringWriter JavaDoc sw = new StringWriter JavaDoc();
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 JavaDoc e)
279         {
280             // should have generated this exception
281
}
282     }
283
284
285     public void testIllegalOrderScreen()
286     {
287         StringWriter JavaDoc sw = new StringWriter JavaDoc();
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 JavaDoc e)
296         {
297             // should have generated this exception
298
}
299     }
300
301
302     public void testIllegalOrderStart()
303     {
304         StringWriter JavaDoc sw = new StringWriter JavaDoc();
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 JavaDoc e)
314         {
315             // should have generated this exception
316
}
317         finally
318         {
319             jsm.end();
320         }
321     }
322     
323     
324     
325     
326     //-------------------------------------------------------------------------
327
// Standard JUnit declarations
328

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 JavaDoc[] args )
338     {
339         String JavaDoc[] name = { THIS_CLASS.getName() };
340         
341         // junit.textui.TestRunner.main( name );
342
// junit.swingui.TestRunner.main( name );
343

344         junit.textui.TestRunner.main( name );
345     }
346     
347     /**
348      *
349      * @exception Exception thrown under any exceptional condition.
350      */

351     protected void setUp() throws Exception JavaDoc
352     {
353         super.setUp();
354         
355         // set ourself up
356
}
357     
358     
359     /**
360      *
361      * @exception Exception thrown under any exceptional condition.
362      */

363     protected void tearDown() throws Exception JavaDoc
364     {
365         // tear ourself down
366

367         
368         super.tearDown();
369     }
370 }
371
372
Popular Tags