|
17 | 17 |
|
18 | 18 | import static org.junit.Assert.*;
|
19 | 19 |
|
20 |
| -import org.junit.Test; |
21 |
| - |
22 | 20 | import java.util.ArrayList;
|
| 21 | +import java.util.Arrays; |
23 | 22 | import java.util.List;
|
24 | 23 |
|
| 24 | +import org.junit.Test; |
| 25 | + |
25 | 26 | public class CompositeExceptionTest {
|
26 | 27 |
|
27 | 28 | private final Throwable ex1 = new Throwable("Ex1");
|
28 | 29 | private final Throwable ex2 = new Throwable("Ex2", ex1);
|
29 | 30 | private final Throwable ex3 = new Throwable("Ex3", ex2);
|
30 | 31 |
|
31 |
| - private final CompositeException compositeEx; |
32 |
| - |
33 | 32 | public CompositeExceptionTest() {
|
34 | 33 | ex1.initCause(ex2);
|
| 34 | + } |
| 35 | + |
| 36 | + private CompositeException getNewCompositeExceptionWithEx123() { |
35 | 37 | List<Throwable> throwables = new ArrayList<Throwable>();
|
36 | 38 | throwables.add(ex1);
|
37 | 39 | throwables.add(ex2);
|
38 | 40 | throwables.add(ex3);
|
39 |
| - compositeEx = new CompositeException(throwables); |
| 41 | + return new CompositeException(throwables); |
| 42 | + } |
| 43 | + |
| 44 | + @Test(timeout = 1000) |
| 45 | + public void testMultipleWithSameCause() { |
| 46 | + Throwable rootCause = new Throwable("RootCause"); |
| 47 | + Throwable e1 = new Throwable("1", rootCause); |
| 48 | + Throwable e2 = new Throwable("2", rootCause); |
| 49 | + Throwable e3 = new Throwable("3", rootCause); |
| 50 | + CompositeException ce = new CompositeException("3 failures with same root cause", Arrays.asList(e1, e2, e3)); |
40 | 51 | }
|
41 | 52 |
|
42 |
| - @Test |
| 53 | + @Test(timeout = 1000) |
43 | 54 | public void testAttachCallingThreadStackParentThenChild() {
|
44 | 55 | CompositeException.attachCallingThreadStack(ex1, ex2);
|
45 | 56 | assertEquals("Ex2", ex1.getCause().getMessage());
|
46 | 57 | }
|
47 | 58 |
|
48 |
| - @Test |
| 59 | + @Test(timeout = 1000) |
49 | 60 | public void testAttachCallingThreadStackChildThenParent() {
|
50 | 61 | CompositeException.attachCallingThreadStack(ex2, ex1);
|
51 | 62 | assertEquals("Ex1", ex2.getCause().getMessage());
|
52 | 63 | }
|
53 | 64 |
|
54 |
| - @Test |
| 65 | + @Test(timeout = 1000) |
55 | 66 | public void testAttachCallingThreadStackAddComposite() {
|
56 |
| - CompositeException.attachCallingThreadStack(ex1, compositeEx); |
| 67 | + CompositeException.attachCallingThreadStack(ex1, getNewCompositeExceptionWithEx123()); |
57 | 68 | assertEquals("Ex2", ex1.getCause().getMessage());
|
58 | 69 | }
|
59 | 70 |
|
60 |
| - @Test |
| 71 | + @Test(timeout = 1000) |
61 | 72 | public void testAttachCallingThreadStackAddToComposite() {
|
| 73 | + CompositeException compositeEx = getNewCompositeExceptionWithEx123(); |
62 | 74 | CompositeException.attachCallingThreadStack(compositeEx, ex1);
|
63 | 75 | assertEquals(CompositeException.CompositeExceptionCausalChain.MESSAGE, compositeEx.getCause().getMessage());
|
64 | 76 | }
|
65 | 77 |
|
66 |
| - @Test |
| 78 | + @Test(timeout = 1000) |
67 | 79 | public void testAttachCallingThreadStackAddCompositeToItself() {
|
| 80 | + CompositeException compositeEx = getNewCompositeExceptionWithEx123(); |
68 | 81 | CompositeException.attachCallingThreadStack(compositeEx, compositeEx);
|
69 | 82 | assertEquals(CompositeException.CompositeExceptionCausalChain.MESSAGE, compositeEx.getCause().getMessage());
|
70 | 83 | }
|
71 | 84 |
|
72 |
| - @Test |
| 85 | + @Test(timeout = 1000) |
73 | 86 | public void testAttachCallingThreadStackAddExceptionsToEachOther() {
|
74 | 87 | CompositeException.attachCallingThreadStack(ex1, ex2);
|
75 | 88 | CompositeException.attachCallingThreadStack(ex2, ex1);
|
|
0 commit comments