package se.raddo.raddose3D.tests;

import org.testng.Assert;
import org.testng.annotations.*;

import se.raddo.raddose3D.Writer;
import se.raddo.raddose3D.WriterString;

public class WriterStringTest {

  @Test
  public void testWriterString() {
    Writer w = new WriterString();

    w.write("asdf");
    w.write("");
    w.write(new StringBuffer("\n"));
    w.write("bla");
    w.close();

    Assert.assertEquals(((WriterString) w).getDataString(), "asdf\nbla");
    System.out.println("@Test - testWriterString");
  }

  @Test
  public void testWriterStringAfterClose() {
    Writer w = new WriterString();
    Boolean exceptionEncountered = false;

    w.write("asdf");
    w.close();

    try {
      w.write("asdf");
    } catch (RuntimeException e) {
      exceptionEncountered = true;
    }
    Assert.assertTrue(exceptionEncountered);

    exceptionEncountered = false;
    try {
      w.write(new StringBuffer("asdf"));
    } catch (RuntimeException e) {
      exceptionEncountered = true;
    }
    Assert.assertTrue(exceptionEncountered);

    System.out.println("@Test - testWriterStringAfterClose");
  }

}

@@ -28,16 +28,45 @@
 tests;%0A%0A
+import java.io.PrintWriter;%0A%0A
 import o
@@ -1143,10 +1143,371 @@
 );%0A  %7D%0A%0A
+%0A  @Test%0A  public void testWriterStringAsOutputStream() %7B%0A    WriterString w = new WriterString();%0A    PrintWriter p = new PrintWriter(w);%0A%0A    p.write(%22asdf%22);%0A    p.write(%22%22);%0A    p.write(%22%5Cn%22);%0A    p.write(%22bla%22);%0A    p.close();%0A%0A    Assert.assertEquals(w.getDataString(), %22asdf%5Cnbla%22);%0A    System.out.println(%22@Test - testWriterStringAsOutputStream%22);%0A  %7D%0A%0A
 %7D%0A

Test Writer as OutputStream