KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > lang > StartupHelperTest


1 /*
2  * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

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 JavaDoc {
16     final SynchronizedRef error = new SynchronizedRef(null);
17
18     ThreadGroup JavaDoc group = new ThreadGroup JavaDoc("group") {
19       public void uncaughtException(Thread JavaDoc t, Throwable JavaDoc e) {
20         error.set(e);
21       }
22     };
23
24     final RuntimeException JavaDoc re = new RuntimeException JavaDoc("da bomb");
25
26     StartupHelper helper = new StartupHelper(group, new StartupHelper.StartupAction() {
27       public void execute() throws Throwable JavaDoc {
28         throw re;
29       }
30     });
31
32     helper.startUp();
33
34     RuntimeException JavaDoc thrown = (RuntimeException JavaDoc) 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 JavaDoc {
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 JavaDoc {
47         ThreadGroup JavaDoc tg = Thread.currentThread().getThreadGroup();
48         if (tg != group) { throw new AssertionError JavaDoc("wrong thread group: " + tg); }
49       }
50     });
51
52     helper.startUp();
53   }
54
55 }
56
Popular Tags