|
37 | 37 | class RollbackRuleTests {
|
38 | 38 |
|
39 | 39 | @Test
|
40 |
| - void foundImmediatelyWithString() { |
41 |
| - RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception.class.getName()); |
42 |
| - assertThat(rr.getDepth(new Exception())).isEqualTo(0); |
| 40 | + void constructorArgumentMustBeThrowableClassWithNonThrowableType() { |
| 41 | + assertThatIllegalArgumentException().isThrownBy(() -> new RollbackRuleAttribute(Object.class)); |
43 | 42 | }
|
44 | 43 |
|
45 | 44 | @Test
|
46 |
| - void foundImmediatelyWithClass() { |
47 |
| - RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception.class); |
48 |
| - assertThat(rr.getDepth(new Exception())).isEqualTo(0); |
| 45 | + void constructorArgumentMustBeThrowableClassWithNullThrowableType() { |
| 46 | + assertThatIllegalArgumentException().isThrownBy(() -> new RollbackRuleAttribute((Class<?>) null)); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void constructorArgumentMustBeStringWithNull() { |
| 51 | + assertThatIllegalArgumentException().isThrownBy(() -> new RollbackRuleAttribute((String) null)); |
49 | 52 | }
|
50 | 53 |
|
51 | 54 | @Test
|
52 | 55 | void notFound() {
|
53 |
| - RollbackRuleAttribute rr = new RollbackRuleAttribute(java.io.IOException.class.getName()); |
| 56 | + RollbackRuleAttribute rr = new RollbackRuleAttribute(IOException.class); |
54 | 57 | assertThat(rr.getDepth(new MyRuntimeException(""))).isEqualTo(-1);
|
55 | 58 | }
|
56 | 59 |
|
57 | 60 | @Test
|
58 |
| - void ancestry() { |
| 61 | + void foundImmediatelyWithString() { |
59 | 62 | RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception.class.getName());
|
60 |
| - // Exception -> Runtime -> NestedRuntime -> MyRuntimeException |
61 |
| - assertThat(rr.getDepth(new MyRuntimeException(""))).isEqualTo(3); |
| 63 | + assertThat(rr.getDepth(new Exception())).isEqualTo(0); |
62 | 64 | }
|
63 | 65 |
|
64 | 66 | @Test
|
65 |
| - void alwaysTrueForThrowable() { |
66 |
| - RollbackRuleAttribute rr = new RollbackRuleAttribute(Throwable.class.getName()); |
67 |
| - assertThat(rr.getDepth(new MyRuntimeException(""))).isGreaterThan(0); |
68 |
| - assertThat(rr.getDepth(new IOException())).isGreaterThan(0); |
69 |
| - assertThat(rr.getDepth(new FatalBeanException(null, null))).isGreaterThan(0); |
70 |
| - assertThat(rr.getDepth(new RuntimeException())).isGreaterThan(0); |
| 67 | + void foundImmediatelyWithClass() { |
| 68 | + RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception.class); |
| 69 | + assertThat(rr.getDepth(new Exception())).isEqualTo(0); |
71 | 70 | }
|
72 | 71 |
|
73 | 72 | @Test
|
74 |
| - void ctorArgMustBeAThrowableClassWithNonThrowableType() { |
75 |
| - assertThatIllegalArgumentException().isThrownBy(() -> new RollbackRuleAttribute(Object.class)); |
| 73 | + void foundInSuperclassHierarchy() { |
| 74 | + RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception.class); |
| 75 | + // Exception -> RuntimeException -> NestedRuntimeException -> MyRuntimeException |
| 76 | + assertThat(rr.getDepth(new MyRuntimeException(""))).isEqualTo(3); |
76 | 77 | }
|
77 | 78 |
|
78 | 79 | @Test
|
79 |
| - void ctorArgMustBeAThrowableClassWithNullThrowableType() { |
80 |
| - assertThatIllegalArgumentException().isThrownBy(() -> new RollbackRuleAttribute((Class<?>) null)); |
| 80 | + void alwaysFoundForThrowable() { |
| 81 | + RollbackRuleAttribute rr = new RollbackRuleAttribute(Throwable.class); |
| 82 | + assertThat(rr.getDepth(new MyRuntimeException(""))).isGreaterThan(0); |
| 83 | + assertThat(rr.getDepth(new IOException())).isGreaterThan(0); |
| 84 | + assertThat(rr.getDepth(new FatalBeanException(null, null))).isGreaterThan(0); |
| 85 | + assertThat(rr.getDepth(new RuntimeException())).isGreaterThan(0); |
81 | 86 | }
|
82 | 87 |
|
83 | 88 | @Test
|
84 |
| - void ctorArgExceptionStringNameVersionWithNull() { |
85 |
| - assertThatIllegalArgumentException().isThrownBy(() -> new RollbackRuleAttribute((String) null)); |
| 89 | + void foundNestedExceptionInEnclosingException() { |
| 90 | + RollbackRuleAttribute rr = new RollbackRuleAttribute(EnclosingException.class); |
| 91 | + assertThat(rr.getDepth(new EnclosingException.NestedException())).isEqualTo(0); |
86 | 92 | }
|
87 | 93 |
|
88 | 94 | @Test
|
89 |
| - void foundEnclosedExceptionWithEnclosingException() { |
90 |
| - RollbackRuleAttribute rr = new RollbackRuleAttribute(EnclosingException.class); |
91 |
| - assertThat(rr.getDepth(new EnclosingException.EnclosedException())).isEqualTo(0); |
| 95 | + void foundWhenNameOfExceptionThrownStartsWithTheNameOfTheRegisteredExceptionType() { |
| 96 | + RollbackRuleAttribute rr = new RollbackRuleAttribute(MyException.class); |
| 97 | + assertThat(rr.getDepth(new MyException2())).isEqualTo(0); |
92 | 98 | }
|
93 | 99 |
|
| 100 | + |
94 | 101 | @SuppressWarnings("serial")
|
95 | 102 | static class EnclosingException extends RuntimeException {
|
96 | 103 |
|
97 | 104 | @SuppressWarnings("serial")
|
98 |
| - static class EnclosedException extends RuntimeException { |
99 |
| - |
| 105 | + static class NestedException extends RuntimeException { |
100 | 106 | }
|
101 | 107 | }
|
102 | 108 |
|
| 109 | + static class MyException extends RuntimeException { |
| 110 | + } |
| 111 | + |
| 112 | + // Name intentionally starts with MyException (including package) but does |
| 113 | + // NOT extend MyException. |
| 114 | + static class MyException2 extends RuntimeException { |
| 115 | + } |
| 116 | + |
103 | 117 | }
|
0 commit comments