I want to test a void type method that writes a String to the stdout.
For this matter my team and I are trying to compare its output with the String / text we expect to see when we call the method.

Note: I'm a newbie both to Java and StackOverflow, so if there's a better way of doing this I'd be thankful to be notified about that.

```
 public static boolean test_printAdequateOption(String txt, double[]
 sol, Formatter out, String expectedOutput) {
         //Obj.
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         PrintStream ps = new PrintStream(baos);
         PrintStream sout = System.out;

         System.setOut(ps);

         printAdequateOption(txt, sol, out);

         System.out.flush();
         System.setOut(sout);

     return  baos.toString().equals(expectedOutput);
 }

```

The thought behind this test is to print the output of the method printAdequateOption to a PrintStream in such way that it allows me to save it as a String and thus compare it to an expected ouput parameter.