@@ -48,11 +48,15 @@ class OutputCapture implements CapturedOutput {
48
48
49
49
private final Deque <SystemCapture > systemCaptures = new ArrayDeque <>();
50
50
51
- private final AtomicReference <String > out = new AtomicReference <>(null );
51
+ private final AtomicReference <Object > out = new AtomicReference <>();
52
52
53
- private final AtomicReference <String > err = new AtomicReference <>(null );
53
+ private final AtomicReference <Object > err = new AtomicReference <>();
54
54
55
- private final AtomicReference <String > all = new AtomicReference <>(null );
55
+ private final AtomicReference <Object > all = new AtomicReference <>();
56
+
57
+ OutputCapture () {
58
+ clearExisting ();
59
+ }
56
60
57
61
/**
58
62
* Push a new system capture session onto the stack.
@@ -128,20 +132,21 @@ void reset() {
128
132
}
129
133
130
134
void clearExisting () {
131
- this .out .set (null );
132
- this .err .set (null );
133
- this .all .set (null );
135
+ this .out .set (new NoOutput () );
136
+ this .err .set (new NoOutput () );
137
+ this .all .set (new NoOutput () );
134
138
}
135
139
136
- private String get (AtomicReference <String > existing , Predicate <Type > filter ) {
140
+ private String get (AtomicReference <Object > existing , Predicate <Type > filter ) {
137
141
Assert .state (!this .systemCaptures .isEmpty (),
138
142
"No system captures found. Please check your output capture registration." );
139
- String result = existing .get ();
140
- if (result == null ) {
141
- result = build (filter );
142
- existing .compareAndSet (null , result );
143
+ Object existingOutput = existing .get ();
144
+ if (existingOutput instanceof String ) {
145
+ return (String ) existingOutput ;
143
146
}
144
- return result ;
147
+ String builtOutput = build (filter );
148
+ existing .compareAndSet (existingOutput , builtOutput );
149
+ return builtOutput ;
145
150
}
146
151
147
152
String build (Predicate <Type > filter ) {
@@ -306,4 +311,8 @@ enum Type {
306
311
307
312
}
308
313
314
+ static class NoOutput {
315
+
316
+ }
317
+
309
318
}
0 commit comments