FileDocCategorySizeDatePackage
IndentingPrintWriterTest.javaAPI DocAndroid 5.1 API4168Thu Mar 12 22:22:12 GMT 2015com.android.internal.util

IndentingPrintWriterTest

public class IndentingPrintWriterTest extends TestCase
Tests for {@link IndentingPrintWriter}.

Fields Summary
private ByteArrayOutputStream
mStream
private PrintWriter
mWriter
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();

        mStream = new ByteArrayOutputStream();
        mWriter = new PrintWriter(mStream);
    
public voidtestAdjustIndentAfterNewline()

        final IndentingPrintWriter pw = new IndentingPrintWriter(mWriter, "  ");

        pw.println("Hello");
        pw.increaseIndent();
        pw.println("World");

        pw.flush();
        assertEquals("Hello\n  World\n", mStream.toString());
    
public voidtestMultipleIndents()

        final IndentingPrintWriter pw = new IndentingPrintWriter(mWriter, "  ");

        pw.print("Hello");
        pw.increaseIndent();
        pw.println();
        pw.print("World");
        pw.increaseIndent();
        pw.println();
        pw.print("And");
        pw.decreaseIndent();
        pw.println();
        pw.print("Goodbye");
        pw.decreaseIndent();
        pw.println();
        pw.print("World");
        pw.println();

        pw.flush();
        assertEquals("Hello\n  World\n    And\n  Goodbye\nWorld\n", mStream.toString());
    
public voidtestWrapping()

        final IndentingPrintWriter pw = new IndentingPrintWriter(mWriter, "", 10);

        pw.print("dog ");
        pw.print("cat ");
        pw.print("cow ");
        pw.print("meow ");

        pw.flush();
        assertEquals("dog cat \ncow meow ", mStream.toString());
    
public voidtestWrappingEmbeddedNewlines()

        final IndentingPrintWriter pw = new IndentingPrintWriter(mWriter, "  ", 10);

        pw.increaseIndent();
        pw.print("Lorem ipsum \ndolor sit \namet, consectetur \nadipiscing elit.");

        pw.flush();
        assertEquals("  Lorem ip\n  sum \n  dolor si\n  t \n  amet, co\n"
                + "  nsectetu\n  r \n  adipisci\n  ng elit.\n", mStream.toString());
    
public voidtestWrappingIndented()

        final IndentingPrintWriter pw = new IndentingPrintWriter(mWriter, "    ", 10);

        pw.increaseIndent();
        pw.print("dog ");
        pw.print("meow ");
        pw.print("a ");
        pw.print("b ");
        pw.print("cow ");

        pw.flush();
        assertEquals("    dog \n    meow \n    a b \n    cow ", mStream.toString());
    
public voidtestWrappingPrefixedGiant()

        final IndentingPrintWriter pw = new IndentingPrintWriter(mWriter, "  ", 10);

        pw.increaseIndent();
        pw.print("foo");
        pw.print("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");

        pw.flush();
        assertEquals("  foo\n  Lorem ip\n  sum dolo\n  r sit am\n  et, cons\n"
                + "  ectetur \n  adipisci\n  ng elit.\n", mStream.toString());
    
public voidtestWrappingSingleGiant()

        final IndentingPrintWriter pw = new IndentingPrintWriter(mWriter, "  ", 10);

        pw.increaseIndent();
        pw.print("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");

        pw.flush();
        assertEquals("  Lorem ip\n  sum dolo\n  r sit am\n  et, cons\n"
                + "  ectetur \n  adipisci\n  ng elit.\n", mStream.toString());