1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.store; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
|
24 |
|
import org.junit.Assert; |
25 |
|
import org.junit.Test; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@version |
31 |
|
@since |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 8 |
Complexity Density: 0.35 |
|
33 |
|
public class TransactionExceptionTest |
34 |
|
{ |
35 |
|
private static final String SIMPLE_TEST_OUT = |
36 |
|
"Caused by:\n" |
37 |
|
+ "java.lang.Exception\n" |
38 |
|
+ "\t" + "One exception.\n" |
39 |
|
+ "java.lang.RuntimeException\n" |
40 |
|
+ "\t" + "Number 2\n" |
41 |
|
+ "java.lang.OutOfMemoryError\n" |
42 |
|
+ "\t" + "Ut oh\n"; |
43 |
|
|
44 |
|
private static final String COMPOUND_TEST_OUT = |
45 |
|
"Caused by:\n" |
46 |
|
+ "java.lang.Exception\n" |
47 |
|
+ "\t" + "something bad happened.\n" |
48 |
|
+ "org.xwiki.store.TransactionException\n" |
49 |
|
+ "\t" + "Caused by:\n" |
50 |
|
+ "\t" + "java.lang.Exception\n" |
51 |
|
+ "\t" + "\t" + "One exception.\n" |
52 |
|
+ "\t" + "java.lang.RuntimeException\n" |
53 |
|
+ "\t" + "\t" + "Number 2\n" |
54 |
|
+ "\t" + "java.lang.OutOfMemoryError\n" |
55 |
|
+ "\t" + "\t" + "Ut oh\n" |
56 |
|
+ "\t" + "\n" |
57 |
|
+ "java.lang.Error\n" |
58 |
|
+ "\t" + "SEGFAULT!\n"; |
59 |
|
|
60 |
|
private static final String NONRECOVERABLE_TEST_OUT = |
61 |
|
"Caused by:\n" |
62 |
|
+ "java.lang.Exception\n" |
63 |
|
+ "\t" + "something bad happened.\n" |
64 |
|
+ "org.xwiki.store.TransactionException\n" |
65 |
|
+ "\t" + "This means there is db corruption\n" |
66 |
|
+ "\t" + "Caused by:\n" |
67 |
|
+ "\t" + "java.lang.Error\n" |
68 |
|
+ "\t" + "\t" + "Corruption!!\n" |
69 |
|
+ "\t" + "\n" |
70 |
|
+ "java.lang.Error\n" |
71 |
|
+ "\t" + "SEGFAULT!\n"; |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
76 |
1 |
@Test... |
77 |
|
public void simpleExceptionTest() |
78 |
|
{ |
79 |
1 |
TransactionException te = this.getException(); |
80 |
1 |
Assert.assertFalse(te.isNonRecoverable()); |
81 |
1 |
Assert.assertEquals("Wrong number of exceptions reported", 3, te.exceptionCount()); |
82 |
1 |
Assert.assertEquals("The wrong exception message was given", SIMPLE_TEST_OUT, te.getMessage()); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
public void compoundExceptionTest() |
87 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
88 |
1 |
TransactionException te = new TransactionException(new ArrayList<Throwable>() {{... |
89 |
1 |
add(new Exception("something bad happened.")); |
90 |
1 |
add(getException()); |
91 |
1 |
add(new Error("SEGFAULT!")); |
92 |
|
}}); |
93 |
1 |
Assert.assertFalse(te.isNonRecoverable()); |
94 |
1 |
Assert.assertEquals("Wrong number of exceptions reported", 5, te.exceptionCount()); |
95 |
1 |
Assert.assertEquals("The wrong exception message was given", COMPOUND_TEST_OUT, te.getMessage()); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void nonRecoverableTest() |
100 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
101 |
1 |
TransactionException te = new TransactionException(new ArrayList<Throwable>() {{... |
102 |
1 |
add(new Exception("something bad happened.")); |
103 |
1 |
add(new TransactionException("This means there is db corruption", |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
1 |
new ArrayList<Throwable>() {{... |
105 |
1 |
add(new Error("Corruption!!")); |
106 |
|
}}, true)); |
107 |
1 |
add(new Error("SEGFAULT!")); |
108 |
|
}}); |
109 |
1 |
Assert.assertTrue(te.isNonRecoverable()); |
110 |
1 |
Assert.assertEquals("Wrong number of exceptions reported", 3, te.exceptionCount()); |
111 |
1 |
Assert.assertEquals("The wrong exception message was given", |
112 |
|
NONRECOVERABLE_TEST_OUT, te.getMessage()); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
115 |
2 |
private TransactionException getException()... |
116 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
117 |
2 |
return new TransactionException(new ArrayList<Throwable>() {{... |
118 |
2 |
add(new Exception("One exception.")); |
119 |
2 |
add(new RuntimeException("Number 2")); |
120 |
2 |
add(new OutOfMemoryError("Ut oh")); |
121 |
|
}}); |
122 |
|
} |
123 |
|
} |