1
+ /**
2
+ * Copyright 2013 Netflix, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package rx .util ;
17
+
18
+ import static org .junit .Assert .*;
19
+
20
+ import org .junit .Test ;
21
+
22
+ import java .util .ArrayList ;
23
+ import java .util .List ;
24
+
25
+ public class CompositeExceptionTest {
26
+
27
+ private final Throwable ex1 = new Throwable ("Ex1" );
28
+ private final Throwable ex2 = new Throwable ("Ex2" , ex1 );
29
+ private final Throwable ex3 = new Throwable ("Ex3" , ex2 );
30
+
31
+ private final CompositeException compositeEx ;
32
+
33
+ public CompositeExceptionTest () {
34
+ List <Throwable > throwables = new ArrayList <Throwable >();
35
+ throwables .add (ex1 );
36
+ throwables .add (ex2 );
37
+ throwables .add (ex3 );
38
+ compositeEx = new CompositeException (throwables );
39
+ }
40
+
41
+ @ Test
42
+ public void testAttachCallingThreadStackParentThenChild () {
43
+ CompositeException .attachCallingThreadStack (ex1 , ex2 );
44
+ assertEquals ("Ex2" , ex1 .getCause ().getMessage ());
45
+ }
46
+
47
+ @ Test
48
+ public void testAttachCallingThreadStackChildThenParent () {
49
+ CompositeException .attachCallingThreadStack (ex2 , ex1 );
50
+ assertEquals ("Ex1" , ex2 .getCause ().getMessage ());
51
+ }
52
+
53
+ @ Test
54
+ public void testAttachCallingThreadStackAddComposite () {
55
+ CompositeException .attachCallingThreadStack (ex1 , compositeEx );
56
+ assertEquals ("Ex2" , ex1 .getCause ().getMessage ());
57
+ }
58
+
59
+ @ Test
60
+ public void testAttachCallingThreadStackAddToComposite () {
61
+ CompositeException .attachCallingThreadStack (compositeEx , ex1 );
62
+ assertEquals (CompositeException .CompositeExceptionCausalChain .MESSAGE , compositeEx .getCause ().getMessage ());
63
+ }
64
+
65
+ @ Test
66
+ public void testAttachCallingThreadStackAddCompositeToItself () {
67
+ CompositeException .attachCallingThreadStack (compositeEx , compositeEx );
68
+ assertEquals (CompositeException .CompositeExceptionCausalChain .MESSAGE , compositeEx .getCause ().getMessage ());
69
+ }
70
+ }
0 commit comments