From 49d02bfdee818772eb4e7c040a5535f5bbee2937 Mon Sep 17 00:00:00 2001 From: Maxim Mikhailov Date: Tue, 5 Mar 2024 03:00:16 +0200 Subject: [PATCH] docs(SortArgs) - Fix bug in ExerciseRunner (#2138) Restores the default `System.out` to fix result printing `System.out` was changed to a custom `printStream`, so `System.out.println(output.equals("1 2 3 4\n"));` printed `true` or `false` to this `printStream` and not the default `System.out`. This causes console output to be empty. --- subjects/java/piscine/SortArgs/README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/subjects/java/piscine/SortArgs/README.md b/subjects/java/piscine/SortArgs/README.md index f835d1ff9..d1d64a97b 100644 --- a/subjects/java/piscine/SortArgs/README.md +++ b/subjects/java/piscine/SortArgs/README.md @@ -28,8 +28,13 @@ public class ExerciseRunner { public static void main(String[] args) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(outputStream); + + var defaultOut = System.out; + System.setOut(printStream); - SortArgs.sort(new String[]{"4","2","1","3"}); + SortArgs.sort(new String[]{"4", "2", "1", "3"}); + System.setOut(defaultOut); + String output = outputStream.toString(); System.out.println(output.equals("1 2 3 4\n")); } @@ -51,4 +56,4 @@ $ [Conditional statement](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html) [String](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html) [Array](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) -[File](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html) \ No newline at end of file +[File](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html)