1 package org.springframework.richclient.exceptionhandling.delegation;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
6 import java.util.List;
7
8 import junit.framework.TestCase;
9
10
11
12
13 public class DefaultExceptionPurgerTests extends TestCase {
14
15
16 private DException d1 = new DException();
17 private BException b2 = new BException(d1);
18 private CException c1 = new CException(b2);
19 private BException b1 = new BException(c1);
20 private AException a1 = new AException(b1);
21
22
23
24
25
26
27
28
29
30
31 public void testIncludedThrowableClassList() {
32 assertEquals(a1, checkIncluded(AException.class));
33 assertEquals(b1, checkIncluded(BException.class));
34 assertEquals(d1, checkIncluded(DException.class));
35 assertEquals(a1, checkIncluded(ZException.class));
36 assertEquals(c1, checkIncluded(CException.class, ZException.class));
37 assertEquals(b1, checkIncluded(BException.class, DException.class));
38 assertEquals(b1, checkIncluded(DException.class, BException.class));
39 }
40
41 public Throwable checkIncluded(Class ... includedThrowableClasses) {
42 return new DefaultExceptionPurger(Arrays.asList(includedThrowableClasses), null).purge(a1);
43 }
44
45
46
47
48
49
50
51
52
53
54 public void testExcludedThrowableClassList() {
55 assertEquals(b1, checkExcluded(AException.class));
56 assertEquals(d1, checkExcluded(BException.class));
57 assertEquals(d1, checkExcluded(DException.class));
58 assertEquals(a1, checkExcluded(ZException.class));
59 assertEquals(b2, checkExcluded(CException.class, ZException.class));
60 assertEquals(d1, checkExcluded(CException.class, DException.class));
61 assertEquals(d1, checkExcluded(DException.class, CException.class));
62 }
63
64 public Throwable checkExcluded(Class ... excludedThrowableClasses) {
65 return new DefaultExceptionPurger(null, Arrays.asList(excludedThrowableClasses)).purge(a1);
66 }
67
68 private class AException extends RuntimeException {
69 private AException(Throwable cause) {
70 super(cause);
71 }
72 }
73 private class BException extends RuntimeException {
74 private BException(Throwable cause) {
75 super(cause);
76 }
77 }
78 private class CException extends RuntimeException {
79 private CException(Throwable cause) {
80 super(cause);
81 }
82 }
83 private class DException extends RuntimeException {
84 }
85 private class ZException extends RuntimeException {
86 }
87
88 }