01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.exception;
05:
06: import org.mortbay.util.MultiException;
07:
08: import junit.framework.TestCase;
09:
10: public class ExceptionHelperTest extends TestCase {
11: public void test() {
12: ExceptionHelperImpl helper = new ExceptionHelperImpl();
13: helper.addHelper(new RuntimeExceptionHelper());
14: helper.addHelper(new MortbayMultiExceptionHelper());
15:
16: Throwable ultimateCause = new AssertionError();
17: Exception proximateCause = new RuntimeException(ultimateCause);
18: Exception top = new TCRuntimeException(proximateCause);
19:
20: check(helper, ultimateCause, proximateCause, top);
21:
22: ultimateCause = new RuntimeException();
23: proximateCause = new MultiException();
24: ((MultiException) proximateCause)
25: .add((Exception) ultimateCause);
26: top = new RuntimeException(proximateCause);
27: check(helper, ultimateCause, proximateCause, top);
28: }
29:
30: private void check(ExceptionHelper helper, Throwable ultimateCause,
31: Exception proximateCause, Exception top) {
32: assertSame(ultimateCause, helper.getUltimateCause(top));
33: assertSame(ultimateCause, helper
34: .getUltimateCause(proximateCause));
35: assertSame(ultimateCause, helper
36: .getUltimateCause(ultimateCause));
37: assertSame(proximateCause, helper.getProximateCause(top));
38: assertSame(ultimateCause, helper
39: .getProximateCause(proximateCause));
40: assertSame(ultimateCause, helper
41: .getProximateCause(ultimateCause));
42: }
43: }
|