Skip to content

Commit a98b17d

Browse files
Add testMultipleWithSameCause UnitTest
Also make tests capable of failing with timeouts. Before the constructor would immediately go into an infinite loop and hang the tests.
1 parent aa8c7c3 commit a98b17d

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

rxjava-core/src/test/java/rx/util/CompositeExceptionTest.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,72 @@
1717

1818
import static org.junit.Assert.*;
1919

20-
import org.junit.Test;
21-
2220
import java.util.ArrayList;
21+
import java.util.Arrays;
2322
import java.util.List;
2423

24+
import org.junit.Test;
25+
2526
public class CompositeExceptionTest {
2627

2728
private final Throwable ex1 = new Throwable("Ex1");
2829
private final Throwable ex2 = new Throwable("Ex2", ex1);
2930
private final Throwable ex3 = new Throwable("Ex3", ex2);
3031

31-
private final CompositeException compositeEx;
32-
3332
public CompositeExceptionTest() {
3433
ex1.initCause(ex2);
34+
}
35+
36+
private CompositeException getNewCompositeExceptionWithEx123() {
3537
List<Throwable> throwables = new ArrayList<Throwable>();
3638
throwables.add(ex1);
3739
throwables.add(ex2);
3840
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));
4051
}
4152

42-
@Test
53+
@Test(timeout = 1000)
4354
public void testAttachCallingThreadStackParentThenChild() {
4455
CompositeException.attachCallingThreadStack(ex1, ex2);
4556
assertEquals("Ex2", ex1.getCause().getMessage());
4657
}
4758

48-
@Test
59+
@Test(timeout = 1000)
4960
public void testAttachCallingThreadStackChildThenParent() {
5061
CompositeException.attachCallingThreadStack(ex2, ex1);
5162
assertEquals("Ex1", ex2.getCause().getMessage());
5263
}
5364

54-
@Test
65+
@Test(timeout = 1000)
5566
public void testAttachCallingThreadStackAddComposite() {
56-
CompositeException.attachCallingThreadStack(ex1, compositeEx);
67+
CompositeException.attachCallingThreadStack(ex1, getNewCompositeExceptionWithEx123());
5768
assertEquals("Ex2", ex1.getCause().getMessage());
5869
}
5970

60-
@Test
71+
@Test(timeout = 1000)
6172
public void testAttachCallingThreadStackAddToComposite() {
73+
CompositeException compositeEx = getNewCompositeExceptionWithEx123();
6274
CompositeException.attachCallingThreadStack(compositeEx, ex1);
6375
assertEquals(CompositeException.CompositeExceptionCausalChain.MESSAGE, compositeEx.getCause().getMessage());
6476
}
6577

66-
@Test
78+
@Test(timeout = 1000)
6779
public void testAttachCallingThreadStackAddCompositeToItself() {
80+
CompositeException compositeEx = getNewCompositeExceptionWithEx123();
6881
CompositeException.attachCallingThreadStack(compositeEx, compositeEx);
6982
assertEquals(CompositeException.CompositeExceptionCausalChain.MESSAGE, compositeEx.getCause().getMessage());
7083
}
7184

72-
@Test
85+
@Test(timeout = 1000)
7386
public void testAttachCallingThreadStackAddExceptionsToEachOther() {
7487
CompositeException.attachCallingThreadStack(ex1, ex2);
7588
CompositeException.attachCallingThreadStack(ex2, ex1);

0 commit comments

Comments
 (0)