FileDocCategorySizeDatePackage
WriterTest.javaAPI DocAndroid 1.5 API11247Wed May 06 22:41:04 BST 2009tests.api.java.io

WriterTest

public class WriterTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtest_appendChar()

tests
java.io.Writer#append(char)

        char testChar = ' ";
        MockWriter writer = new MockWriter(20);
        writer.append(testChar);
        assertEquals(String.valueOf(testChar), String.valueOf(writer
                .getContents()));
        writer.close();

        Writer tobj = new Support_ASimpleWriter(2);
        tobj.append('a");
        tobj.append('b");
        assertEquals("Wrong stuff written!", "ab", tobj.toString());
        try {
            tobj.append('c");
            fail("IOException not thrown!");
        } catch (IOException e) {
            // expected
        }
    
public voidtest_appendCharSequence()

tests
java.io.Writer#append(CharSequence)

        String testString = "My Test String";
        MockWriter writer = new MockWriter(20);
        writer.append(testString);
        assertEquals(testString, String.valueOf(writer.getContents()));
        writer.close();

        Writer tobj = new Support_ASimpleWriter(20);
        tobj.append(testString);
        assertEquals("Wrong stuff written!", testString, tobj.toString());
        try {
            tobj.append(testString);
            fail("IOException not thrown!");
        } catch (IOException e) {
            // expected
        }
    
public voidtest_appendCharSequenceIntInt()

tests
java.io.Writer#append(CharSequence, int, int)

        String testString = "My Test String";
        MockWriter writer = new MockWriter(20);
        writer.append(testString, 1, 3);
        assertEquals(testString.substring(1, 3), String.valueOf(writer
                .getContents()));
        writer.close();

        Writer tobj = new Support_ASimpleWriter(21);
        testString = "0123456789abcdefghijABCDEFGHIJ";
        tobj.append(testString, 0, 5);
        assertEquals("Wrong stuff written!", "01234", tobj.toString());
        tobj.append(testString, 10, 15);
        assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
        tobj.append(testString, 20, 30);
        assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
        try {
            tobj.append(testString, 30, 31);
            fail("IndexOutOfBoundsException not thrown!");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }
        tobj.append(testString, 20, 21); // Just fill the writer to its limit!
        try {
            tobj.append(testString, 29, 30);
            fail("IOException not thrown!");
        } catch (IOException e) {
            // expected
        }
    
public voidtest_appendCharSequenceIntInt_Exception()

tests
java.io.Writer#append(CharSequence, int, int)

        String testString = "My Test String";
        Writer tobj = new Support_ASimpleWriter(21);
        try {
            tobj.append(testString, 30, 31);
            fail("IndexOutOfBoundsException not thrown!");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }
        try {
            tobj.append(testString, -1, 1);
            fail("IndexOutOfBoundsException not thrown!");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }
        try {
            tobj.append(testString, 0, -1);
            fail("IndexOutOfBoundsException not thrown!");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }
    
public voidtest_write$C()

        Writer tobj = new Support_ASimpleWriter(21);
        tobj.write("01234".toCharArray());
        assertEquals("Wrong stuff written!", "01234", tobj.toString());
        tobj.write("abcde".toCharArray());
        assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
        tobj.write("ABCDEFGHIJ".toCharArray());
        assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
        tobj.write("z".toCharArray()); // Just fill the writer to its limit!
        try {
            tobj.write("LES JEUX SONT FAITS".toCharArray());
            fail("IOException not thrown!");
        } catch (IOException e) {
            // expected
        }
    
public voidtest_writeI()

        Writer tobj = new Support_ASimpleWriter(2);
        tobj.write('a");
        tobj.write('b");
        assertEquals("Wrong stuff written!", "ab", tobj.toString());
        try {
            tobj.write('c");
            fail("IOException not thrown!");
        } catch (IOException e) {
            // expected
        }
    
public voidtest_writeLjava_lang_String()

        Writer tobj = new Support_ASimpleWriter(21);
        tobj.write("01234");
        assertEquals("Wrong stuff written!", "01234", tobj.toString());
        tobj.write("abcde");
        assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
        tobj.write("ABCDEFGHIJ");
        assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
        tobj.write("z"); // Just fill the writer to its limit!
        try {
            tobj.write("LES JEUX SONT FAITS");
            fail("IOException not thrown!");
        } catch (IOException e) {
            // expected
        }
    
public voidtest_writeLjava_lang_StringII()

tests
java.io.PrintWriter#write(java.lang.String, int, int)

        String testString;
        Writer tobj = new Support_ASimpleWriter(21);
        testString = "0123456789abcdefghijABCDEFGHIJ";
        tobj.write(testString, 0, 5);
        assertEquals("Wrong stuff written!", "01234", tobj.toString());
        tobj.write(testString, 10, 5);
        assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
        tobj.write(testString, 20, 10);
        assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
        try {
            tobj.write(testString, 30, 1);
            fail("IndexOutOfBoundsException not thrown!");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }
        tobj.write(testString, 20, 1); // Just fill the writer to its limit!
        try {
            tobj.write(testString, 29, 1);
            fail("IOException not thrown!");
        } catch (IOException e) {
            // expected
        }
    
public voidtest_writeLjava_lang_StringII_Exception()

tests
java.io.Writer#append(CharSequence, int, int)

        String testString = "My Test String";
        Writer tobj = new Support_ASimpleWriter(21);
        try {
            tobj.write(testString, 30, 31);
            fail("IndexOutOfBoundsException not thrown!");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }
        try {
            tobj.write(testString, -1, 1);
            fail("IndexOutOfBoundsException not thrown!");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }
        try {
            tobj.write(testString, 0, -1);
            fail("IndexOutOfBoundsException not thrown!");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }