@@ -48,11 +48,15 @@ class OutputCapture implements CapturedOutput {
4848
4949 private final Deque <SystemCapture > systemCaptures = new ArrayDeque <>();
5050
51- private final AtomicReference <String > out = new AtomicReference <>(null );
51+ private final AtomicReference <Object > out = new AtomicReference <>();
5252
53- private final AtomicReference <String > err = new AtomicReference <>(null );
53+ private final AtomicReference <Object > err = new AtomicReference <>();
5454
55- private final AtomicReference <String > all = new AtomicReference <>(null );
55+ private final AtomicReference <Object > all = new AtomicReference <>();
56+
57+ OutputCapture () {
58+ clearExisting ();
59+ }
5660
5761 /**
5862 * Push a new system capture session onto the stack.
@@ -128,20 +132,21 @@ void reset() {
128132 }
129133
130134 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 () );
134138 }
135139
136- private String get (AtomicReference <String > existing , Predicate <Type > filter ) {
140+ private String get (AtomicReference <Object > existing , Predicate <Type > filter ) {
137141 Assert .state (!this .systemCaptures .isEmpty (),
138142 "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 ;
143146 }
144- return result ;
147+ String builtOutput = build (filter );
148+ existing .compareAndSet (existingOutput , builtOutput );
149+ return builtOutput ;
145150 }
146151
147152 String build (Predicate <Type > filter ) {
@@ -306,4 +311,8 @@ enum Type {
306311
307312 }
308313
314+ static class NoOutput {
315+
316+ }
317+
309318}
0 commit comments