FileDocCategorySizeDatePackage
BufferedReaderTest.javaAPI DocAndroid 1.5 API4378Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.tests.java.io

BufferedReaderTest

public class BufferedReaderTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtest_markI()

tests
java.io.BufferedReader#mark(int)

        BufferedReader buf = new BufferedReader(new StringReader("01234"), 2);

        try {
            buf.mark(-1);
            fail("Test 1: IllegalArgumentException expected.");
        } catch (IllegalArgumentException e) {
            // Expected.
        }
               
        buf.mark(3);
        char[] chars = new char[3];
        int result = buf.read(chars);
        assertEquals(3, result);
        assertEquals("Assert 0:", '0", chars[0]);
        assertEquals("Assert 1:", '1", chars[1]);
        assertEquals("Assert 2:", '2", chars[2]);
        assertEquals("Assert 3:", '3", buf.read());

        buf = new BufferedReader(new StringReader("01234"), 2);
        buf.mark(3);
        chars = new char[4];
        result = buf.read(chars);
        assertEquals("Assert 4:", 4, result);
        assertEquals("Assert 5:", '0", chars[0]);
        assertEquals("Assert 6:", '1", chars[1]);
        assertEquals("Assert 7:", '2", chars[2]);
        assertEquals("Assert 8:", '3", chars[3]);
        assertEquals("Assert 9:", '4", buf.read());
        assertEquals("Assert 10:", -1, buf.read());

        BufferedReader reader = new BufferedReader(new StringReader("01234"));
        reader.mark(Integer.MAX_VALUE);
        reader.read();
        reader.close();
        
        try {
            reader.mark(1);
            fail("Test 2: IOException expected.");
        } catch (IOException e) {
            // Expected.
        }
    
public voidtest_read$CII()

tests
java.io.BufferedReader#read(char[], int, int)

        char[] in = {'L", 'o", 'r", 'e", 'm"};
        char[] ch = new char[3];
        BufferedReader reader = new BufferedReader(new CharArrayReader(in));
        
        try {
            reader.read(null, 1, 0);
            fail("Test 1: NullPointerException expected.");
        } catch (NullPointerException e) {
            // Expected.
        }

        try {
            reader.read(ch , -1, 1);
            fail("Test 2: IndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected.
        }
        
        try {
            reader.read(ch , 1, -1);
            fail("Test 3: IndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected.
        }

        try {
            reader.read(ch, 1, 3);
            fail("Test 4: IndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected.
        }

        reader.close();
        try {
            reader.read(ch, 1, 1);
            fail("Test 5: IOException expected.");
        } catch (IOException e) {
            // Expected.
        }