package ch.deletescape.jterm.io;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

import org.junit.Test;

public class MutablePrinterTest {
  private static final String LINESEPERATOR = System.lineSeparator();

  @Test
  public void printTest() {
    MockOutputstream out = new MockOutputstream();
    MutablePrinter printer = new MutablePrinter(new PrintStream(out));
    assertThat(printer.isMuted(), is(false));
    assertThat(printer.print("Test"), is("Test"));
    assertThat(out.sb.toString(), is("Test"));
  }

  @Test
  public void printlnTest() {
    MockOutputstream out = new MockOutputstream();
    MutablePrinter printer = new MutablePrinter(new PrintStream(out));
    assertThat(printer.println("Test"), is("Test"));
    assertThat(out.sb.toString(), is("Test" + LINESEPERATOR));
  }

  @Test
  public void printMutedTest() {
    MockOutputstream out = new MockOutputstream();
    MutablePrinter printer = new MutablePrinter(new PrintStream(out));
    assertThat(printer.mute(true), is(false));
    assertThat(printer.isMuted(), is(true));
    assertThat(printer.print("Test"), is("Test"));
    assertThat(out.sb.toString(), is(""));
  }

  @Test
  public void printForcedTest() {
    MockOutputstream out = new MockOutputstream();
    MutablePrinter printer = new MutablePrinter(new PrintStream(out));
    assertThat(printer.mute(true), is(false));
    assertThat(printer.forced().print("Test"), is("Test"));
    assertThat(out.sb.toString(), is("Test"));
  }

  class MockOutputstream extends OutputStream {
    StringBuilder sb = new StringBuilder();

    @Override
    public void write(int b) throws IOException {
      sb.append((char) b);
    }

  }
}

@@ -668,240 +668,1181 @@
 rint
-lnTest() %7B%0A    MockOutputstream out = new MockOutputstream();%0A    MutablePrinter printer = new MutablePrinter(new PrintStream(out));%0A    assertThat(printer.println(%22Test%22), is(%22Test%22));%0A    assertThat(out.sb.toString(), is(%22Test%22 + 
+NullTest() %7B%0A    MockOutputstream out = new MockOutputstream();%0A    MutablePrinter printer = new MutablePrinter(new PrintStream(out));%0A    assertThat(printer.print(null), is((String) null));%0A    assertThat(out.sb.toString(), is(%22null%22));%0A  %7D%0A%0A  @Test%0A  public void toggleMuteTest() %7B%0A    MockOutputstream out = new MockOutputstream();%0A    MutablePrinter printer = new MutablePrinter(new PrintStream(out));%0A    assertThat(printer.isMuted(), is(false));%0A    assertThat(printer.toggleMute(), is(true));%0A    assertThat(printer.isMuted(), is(true));%0A    assertThat(printer.toggleMute(), is(false));%0A    assertThat(printer.isMuted(), is(false));%0A  %7D%0A%0A  @Test%0A  public void printlnTest() %7B%0A    MockOutputstream out = new MockOutputstream();%0A    MutablePrinter printer = new MutablePrinter(new PrintStream(out));%0A    assertThat(printer.println(%22Test%22), is(%22Test%22));%0A    assertThat(out.sb.toString(), is(%22Test%22 + LINESEPERATOR));%0A  %7D%0A%0A  @Test%0A  public void printlnNoParamTest() %7B%0A    MockOutputstream out = new MockOutputstream();%0A    MutablePrinter printer = new MutablePrinter(new PrintStream(out));%0A    assertThat(printer.println(), is(%22%22));%0A    assertThat(out.sb.toString(), is(
 LINE
@@ -2536,16 +2536,292 @@
 );%0A  %7D%0A%0A
+  public void printForcedNotMutedTest() %7B%0A    MockOutputstream out = new MockOutputstream();%0A    MutablePrinter printer = new MutablePrinter(new PrintStream(out));%0A    assertThat(printer.forced().print(%22Test%22), is(%22Test%22));%0A    assertThat(out.sb.toString(), is(%22Test%22));%0A  %7D%0A%0A
   class 

Add additional tests for MutablePrinter