KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > MainTest


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob;
5
6 import java.io.ByteArrayInputStream JavaDoc;
7
8 import junit.framework.TestCase;
9
10 /**
11  *
12  */

13 public class MainTest extends TestCase {
14
15     // test oddjob args past through
16
public void testInit() {
17         Main m = new Main();
18         Oddjob oj = m.init(new String JavaDoc[] { "-f", "oddjob.xml", "x" } );
19         
20         assertEquals(1, oj.getArgs().length);
21         assertEquals("x", oj.getArgs()[0]);
22     }
23     
24     public static class R implements Runnable JavaDoc, Stoppable {
25         Thread JavaDoc t;
26         public void run() {
27             t = new Thread JavaDoc(new Runnable JavaDoc() {
28                 public void run() {
29                     synchronized (this) {
30                         try {
31                             wait();
32                         } catch (InterruptedException JavaDoc e) {
33                             // continue
34
}
35                     }
36                 }
37             });
38             t.start();
39         }
40         public void stop() {
41             t.interrupt();
42         }
43     }
44     
45     public void testShutdownHook() throws Exception JavaDoc {
46         String JavaDoc xml = "<oddjob><r class='" + R.class.getName() + "'/></oddjob>";
47         Oddjob oj = new Oddjob();
48         oj.setInput(new ByteArrayInputStream JavaDoc(xml.getBytes()));
49         oj.run();
50         
51         Thread.sleep(1000);
52         
53         Main.ShutdownHook hook = new Main.ShutdownHook(oj);
54         hook.run();
55         
56     }
57     
58 }
59
Popular Tags