FileDocCategorySizeDatePackage
PrintWriterTest.javaAPI DocAndroid 1.5 API2489Wed May 06 22:42:02 BST 2009android.core

PrintWriterTest

public class PrintWriterTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestPrintWriter()

        String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
        StringWriter aa = new StringWriter();
        PrintWriter a = new PrintWriter(aa);

        try {
            a.write(str, 0, 26);
            a.write('X");

            assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzX", aa.toString());

            a.write("alphabravodelta", 5, 5);
            a.append('X");
            assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoX", aa.toString());
            a.append("omega");
            assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoXomega", aa.toString());
            a.print("ZZZ");
            assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoXomegaZZZ", aa.toString());
        } finally {
            a.close();
        }

        StringWriter ba = new StringWriter();
        PrintWriter b = new PrintWriter(ba);
        try {
            b.print(true);
            b.print((char) 'A");
            b.print("BCD".toCharArray());
            b.print((double) 1.2);
            b.print((float) 3);
            b.print((int) 4);
            b.print((long) 5);
            assertEquals("trueABCD1.23.045", ba.toString());
            b.println();
            b.println(true);
            b.println((char) 'A");
            b.println("BCD".toCharArray());
            b.println((double) 1.2);
            b.println((float) 3);
            b.println((int) 4);
            b.println((long) 5);
            b.print("THE END");
            assertEquals("trueABCD1.23.045\ntrue\nA\nBCD\n1.2\n3.0\n4\n5\nTHE END", ba.toString());
        } finally {
            b.close();
        }