01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.lang;
06:
07: import EDU.oswego.cs.dl.util.concurrent.SynchronizedRef;
08:
09: 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,
27: new StartupHelper.StartupAction() {
28: public void execute() throws Throwable {
29: throw re;
30: }
31: });
32:
33: helper.startUp();
34:
35: RuntimeException thrown = (RuntimeException) error.get();
36: if (re == null) {
37: fail("no exception delivered to group");
38: }
39:
40: assertTrue(thrown == re);
41: }
42:
43: public void testGroup() throws Throwable {
44: final TCThreadGroup group = new TCThreadGroup(
45: new ThrowableHandler(new NullTCLogger()));
46:
47: StartupHelper helper = new StartupHelper(group,
48: new StartupHelper.StartupAction() {
49: public void execute() throws Throwable {
50: ThreadGroup tg = Thread.currentThread()
51: .getThreadGroup();
52: if (tg != group) {
53: throw new AssertionError(
54: "wrong thread group: " + tg);
55: }
56: }
57: });
58:
59: helper.startUp();
60: }
61:
62: }
|