40
40
public class DefaultExceptionRecorderTest {
41
41
42
42
private final static Logger logger = LogManager .getLogger (DefaultExceptionRecorderTest .class );
43
+ private final static long START_TIME = 1 ;
43
44
44
45
ExceptionChainSampler exceptionChainSampler = new ExceptionChainSampler (1000 );
45
46
ExceptionWrapperFactory exceptionWrapperFactory = new ExceptionWrapperFactory (10 , 1048 );
46
47
47
- long START_TIME = 1 ;
48
48
49
-
50
- class TestExceptionStorage implements ExceptionStorage {
49
+ static class TestExceptionStorage implements ExceptionStorage {
51
50
52
51
List <ExceptionWrapper > wrappers ;
53
52
public List <ExceptionWrapper > outputStream ;
@@ -59,7 +58,7 @@ public TestExceptionStorage() {
59
58
60
59
@ Override
61
60
public void store (List <ExceptionWrapper > wrappers ) {
62
- logger .error (wrappers );
61
+ logger .info (wrappers );
63
62
this .wrappers .addAll (wrappers );
64
63
}
65
64
@@ -85,7 +84,7 @@ public List<ExceptionWrapper> getOutputStream() {
85
84
}
86
85
}
87
86
88
- private Function <Throwable , Throwable > getThrowableFunction (
87
+ private static Function <Throwable , Throwable > getThrowableFunction (
89
88
DefaultExceptionRecorder recorder ,
90
89
List <Throwable > throwable
91
90
) {
@@ -112,11 +111,11 @@ public void testRecordNothing() {
112
111
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder (
113
112
exceptionChainSampler , exceptionWrapperFactory , context
114
113
);
115
- Function <Throwable , Throwable > throwableFunction = getThrowableFunction (
114
+ Function <Throwable , Throwable > recordThrowable = getThrowableFunction (
116
115
exceptionRecorder , exceptions
117
116
);
118
117
119
- exceptionRecorder . recordException (null , 0 );
118
+ recordThrowable . apply (null );
120
119
exceptionRecorder .close ();
121
120
122
121
List <ExceptionWrapper > expected = new ArrayList <>();
@@ -133,18 +132,18 @@ public void testRecordException() {
133
132
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder (
134
133
exceptionChainSampler , exceptionWrapperFactory , context
135
134
);
136
- Function <Throwable , Throwable > throwableFunction = getThrowableFunction (
135
+ Function <Throwable , Throwable > recordThrowable = getThrowableFunction (
137
136
exceptionRecorder , exceptions
138
137
);
139
138
140
139
List <ExceptionWrapper > expected = null ;
141
140
List <ExceptionWrapper > actual = null ;
142
141
143
142
try {
144
- level3Error (throwableFunction );
143
+ level3Error (recordThrowable );
145
144
} catch (Throwable e ) {
146
145
expected = newExceptionWrappers (e , START_TIME , 1 );
147
- exceptionRecorder . recordException ( e , START_TIME );
146
+ recordThrowable . apply ( e );
148
147
actual = exceptionStorage .getWrappers ();
149
148
Assertions .assertTrue (actual .isEmpty ());
150
149
}
@@ -161,7 +160,7 @@ public void testRecordNotChainedException() {
161
160
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder (
162
161
exceptionChainSampler , exceptionWrapperFactory , context
163
162
);
164
- Function <Throwable , Throwable > throwableFunction = getThrowableFunction (
163
+ Function <Throwable , Throwable > recordThrowable = getThrowableFunction (
165
164
exceptionRecorder , exceptions
166
165
);
167
166
@@ -173,10 +172,9 @@ public void testRecordNotChainedException() {
173
172
Throwable throwable = null ;
174
173
175
174
try {
176
- notChainedException (throwableFunction );
175
+ notChainedException (recordThrowable );
177
176
} catch (Throwable e ) {
178
177
expected1 = newExceptionWrappers (exceptions .get (exceptions .size () - 2 ), START_TIME , 1 );
179
- exceptionRecorder .recordException (e , START_TIME );
180
178
logger .warn (exceptionStorage .getWrappers ());
181
179
actual1 = new ArrayList <>(exceptionStorage .getWrappers ());
182
180
throwable = e ;
@@ -204,18 +202,17 @@ public void testRecordRethrowGivenException() {
204
202
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder (
205
203
exceptionChainSampler , exceptionWrapperFactory , context
206
204
);
207
- Function <Throwable , Throwable > throwableFunction = getThrowableFunction (
205
+ Function <Throwable , Throwable > recordThrowable = getThrowableFunction (
208
206
exceptionRecorder , exceptions
209
207
);
210
208
211
209
List <ExceptionWrapper > expected = null ;
212
210
List <ExceptionWrapper > actual = null ;
213
211
214
212
try {
215
- rethrowGivenException (throwableFunction );
213
+ rethrowGivenException (recordThrowable );
216
214
} catch (Throwable e ) {
217
215
expected = newExceptionWrappers (e , START_TIME , 1 );
218
- exceptionRecorder .recordException (e , START_TIME );
219
216
actual = exceptionStorage .getWrappers ();
220
217
Assertions .assertTrue (actual .isEmpty ());
221
218
}
0 commit comments