Code example for CharArrayReader

Methods: close, read

0
     * java.io.CharArrayReader#read(char[], int, int) 
     */ 
    public void test_read$CII() throws IOException { 
        // Test for method int java.io.CharArrayReader.read(char [], int, int) 
        char[] c = new char[11];
        cr = new CharArrayReader(hw);
        cr.read(c, 1, 10);
        assertTrue("Test 1: Read returned incorrect chars.",
                new String(c, 1, 10).equals(new String(hw, 0, 10)));
 
        // Illegal argument checks. 
        try { 
            cr.read(null, 1, 0);
            fail("Test 2: NullPointerException expected.");
        } catch (NullPointerException e) {
            // Expected. 
        } 
 
        try { 
            cr.read(c , -1, 1);
            fail("Test 3: ArrayIndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected 
        } 
 
        try { 
            cr.read(c , 1, -1);
            fail("Test 4: ArrayIndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected 
        } 
 
        try { 
            cr.read(c, 1, c.length);
            fail("Test 5: ArrayIndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected 
        } 
 
        cr.close();
        try { 
            cr.read(c, 1, 1);
            fail("Test 6: IOException expected.");
        } catch (IOException e) {
            // Expected. 
        } 
    }