1 4 package org.oddjob; 5 6 import java.io.ByteArrayInputStream ; 7 8 import junit.framework.TestCase; 9 10 13 public class MainTest extends TestCase { 14 15 public void testInit() { 17 Main m = new Main(); 18 Oddjob oj = m.init(new String [] { "-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 , Stoppable { 25 Thread t; 26 public void run() { 27 t = new Thread (new Runnable () { 28 public void run() { 29 synchronized (this) { 30 try { 31 wait(); 32 } catch (InterruptedException e) { 33 } 35 } 36 } 37 }); 38 t.start(); 39 } 40 public void stop() { 41 t.interrupt(); 42 } 43 } 44 45 public void testShutdownHook() throws Exception { 46 String xml = "<oddjob><r class='" + R.class.getName() + "'/></oddjob>"; 47 Oddjob oj = new Oddjob(); 48 oj.setInput(new ByteArrayInputStream (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 |