Skip to content

Commit

Permalink
More tests cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Bencodes committed Jan 21, 2022
1 parent 7773e9a commit 911ea81
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,11 @@ private void maybePerformGc() {
public static class WorkerIO implements AutoCloseable {

private final PrintStream originalOutputStream;
private final PrintStream originalErrorStream;
private final AutoCloseable restore;

@VisibleForTesting
WorkerIO(
PrintStream originalOutputStream, PrintStream originalErrorStream, AutoCloseable restore) {
WorkerIO(PrintStream originalOutputStream, AutoCloseable restore) {
this.originalOutputStream = originalOutputStream;
this.originalErrorStream = originalErrorStream;
this.restore = restore;
}

Expand All @@ -542,13 +539,11 @@ public static class WorkerIO implements AutoCloseable {
public static WorkerIO redirectSystemStreams() throws IOException {
// Save the original streams
PrintStream originalOutputStream = System.out;
PrintStream originalErrorStream = System.err;

// Redirect System.out to System.err
System.setOut(originalErrorStream);
System.setOut(System.err);

return new WorkerIO(
originalOutputStream, originalErrorStream, () -> System.setOut(originalOutputStream));
return new WorkerIO(originalOutputStream, () -> System.setOut(originalOutputStream));
}

/** Returns the original output stream most commonly provided by {@link System#out} */
Expand All @@ -557,12 +552,6 @@ PrintStream getOriginalOutputStream() {
return originalOutputStream;
}

/** Returns the original error stream most commonly provided by {@link System#err} */
@VisibleForTesting
PrintStream getOriginalErrorStream() {
return originalErrorStream;
}

@Override
public void close() throws Exception {
restore.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ public void testWorkerIO_doesWrapSystemStreams() throws Exception {
assertThat(io.getOriginalOutputStream()).isSameInstanceAs(outputBuffer);
assertThat(System.out).isSameInstanceAs(errorBuffer);

assertThat(io.getOriginalErrorStream()).isSameInstanceAs(errorBuffer);
assertThat(System.err).isSameInstanceAs(errorBuffer);
} finally {
// Swap back in the original streams
Expand Down

0 comments on commit 911ea81

Please sign in to comment.