KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > exception > ExceptionHelperTest


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

4 package com.tc.exception;
5
6 import org.mortbay.util.MultiException;
7
8 import junit.framework.TestCase;
9
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 JavaDoc ultimateCause = new AssertionError JavaDoc();
17     Exception JavaDoc proximateCause = new RuntimeException JavaDoc(ultimateCause);
18     Exception JavaDoc top = new TCRuntimeException(proximateCause);
19     
20     check(helper, ultimateCause, proximateCause, top);
21
22     ultimateCause = new RuntimeException JavaDoc();
23     proximateCause = new MultiException();
24     ((MultiException)proximateCause).add((Exception JavaDoc)ultimateCause);
25     top = new RuntimeException JavaDoc(proximateCause);
26     check(helper, ultimateCause, proximateCause, top);
27   }
28
29   private void check(ExceptionHelper helper, Throwable JavaDoc ultimateCause, Exception JavaDoc proximateCause, Exception JavaDoc top) {
30     assertSame(ultimateCause, helper.getUltimateCause(top));
31     assertSame(ultimateCause, helper.getUltimateCause(proximateCause));
32     assertSame(ultimateCause, helper.getUltimateCause(ultimateCause));
33     assertSame(proximateCause, helper.getProximateCause(top));
34     assertSame(ultimateCause, helper.getProximateCause(proximateCause));
35     assertSame(ultimateCause, helper.getProximateCause(ultimateCause));
36   }
37 }
38
Popular Tags