Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ class OutputCapture implements CapturedOutput {

private final Deque<SystemCapture> systemCaptures = new ArrayDeque<>();

private final AtomicReference<String> out = new AtomicReference<>(null);
private final AtomicReference<Object> out = new AtomicReference<>();

private final AtomicReference<String> err = new AtomicReference<>(null);
private final AtomicReference<Object> err = new AtomicReference<>();

private final AtomicReference<String> all = new AtomicReference<>(null);
private final AtomicReference<Object> all = new AtomicReference<>();

OutputCapture() {
clearExisting();
}

/**
* Push a new system capture session onto the stack.
Expand Down Expand Up @@ -128,20 +132,21 @@ void reset() {
}

void clearExisting() {
this.out.set(null);
this.err.set(null);
this.all.set(null);
this.out.set(new NoOutput());
this.err.set(new NoOutput());
this.all.set(new NoOutput());
}

private String get(AtomicReference<String> existing, Predicate<Type> filter) {
private String get(AtomicReference<Object> existing, Predicate<Type> filter) {
Assert.state(!this.systemCaptures.isEmpty(),
"No system captures found. Please check your output capture registration.");
String result = existing.get();
if (result == null) {
result = build(filter);
existing.compareAndSet(null, result);
Object existingOutput = existing.get();
if (existingOutput instanceof String) {
return (String) existingOutput;
}
return result;
String builtOutput = build(filter);
existing.compareAndSet(existingOutput, builtOutput);
return builtOutput;
}

String build(Predicate<Type> filter) {
Expand Down Expand Up @@ -306,4 +311,8 @@ enum Type {

}

static class NoOutput {

}

}