title: Java: test System output including "new lines" with assertEquals
body: <p>I'm currently writing a Unit Test for the Strategy Design Pattern. I'm comparing the System output with a string in the assertEquals method.The output looks the same but my test keeps failing.. . I'm thinking that I'm forgetting something to do with new lines or tabs?</p>
  
  <p>My Unit Test:</p>
  
  <pre><code>import static org.junit.Assert.*;
  
  import java.io.ByteArrayOutputStream;
  import java.io.PrintStream;
  
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Test;
  
  public class MiniDuck1Test {
  
      private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
      private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
  
      @Before
      public void setUpStreams() {
          System.setOut(new PrintStream(outContent));
          System.setErr(new PrintStream(errContent));
      }
  
      @After
      public void cleanUpStreams() {
          System.setOut(null);
          System.setErr(null);
      }
  
      @Test
      public void testDuck1() {       
          Duck mallard = new MallardDuck();
          mallard.performQuack();
          mallard.performFly();
  
          Duck model = new ModelDuck();
          model.performFly();
          model.setFlyBehavior(new FlyRocketPowered());
          model.performFly();
  
          assertEquals("Quack\nI'm flying!!\nI can't fly\nI'm flying with a rocket", outContent.toString().trim());
      }
  }
  </code></pre>
  
  <p>Output (second and third line appear red):</p>
  
  <pre><code>Quack
  I'm flying!!
  I can't fly
  I'm flying with a rocket
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>The quickest solution seemed to be adding an "\r" in front of my "\n". Multiple answers informed me that this needs to be done for Windows. After applying this my assertEquals looked like:</p>
  
  <pre><code>assertEquals("Quack\r\nI'm flying!!\r\nI can't fly\r\nI'm flying with a rocket", outContent.toString().trim());
  </code></pre>
  
  <p>Also: I forgot to mention that most of the code came from the book: "Head First Design Patterns" by Eric Freeman, Elisabeth Robson, Bert Bates and Kathy Sierra.</p>