1 5 package com.tc.lang; 6 7 import EDU.oswego.cs.dl.util.concurrent.SynchronizedRef; 8 9 import com.tc.logging.NullTCLogger; 10 11 import junit.framework.TestCase; 12 13 public class StartupHelperTest extends TestCase { 14 15 public void testException() throws Throwable { 16 final SynchronizedRef error = new SynchronizedRef(null); 17 18 ThreadGroup group = new ThreadGroup ("group") { 19 public void uncaughtException(Thread t, Throwable e) { 20 error.set(e); 21 } 22 }; 23 24 final RuntimeException re = new RuntimeException ("da bomb"); 25 26 StartupHelper helper = new StartupHelper(group, new StartupHelper.StartupAction() { 27 public void execute() throws Throwable { 28 throw re; 29 } 30 }); 31 32 helper.startUp(); 33 34 RuntimeException thrown = (RuntimeException ) error.get(); 35 if (re == null) { 36 fail("no exception delivered to group"); 37 } 38 39 assertTrue(thrown == re); 40 } 41 42 public void testGroup() throws Throwable { 43 final TCThreadGroup group = new TCThreadGroup(new ThrowableHandler(new NullTCLogger())); 44 45 StartupHelper helper = new StartupHelper(group, new StartupHelper.StartupAction() { 46 public void execute() throws Throwable { 47 ThreadGroup tg = Thread.currentThread().getThreadGroup(); 48 if (tg != group) { throw new AssertionError ("wrong thread group: " + tg); } 49 } 50 }); 51 52 helper.startUp(); 53 } 54 55 } 56 | Popular Tags |