Code example for CharArrayWriter

Methods: appendflushtoString

0
        } 
    } 
 
    public void test_appendLjava_langCharSequenceII() { 
        String testString = "My Test String";
        CharArrayWriter writer = new CharArrayWriter(10);
 
        // Illegal argument checks. 
        try { 
            writer.append(testString, -1, 0);
            fail("Test 1: IndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected. 
        } 
        try { 
            writer.append(testString, 0, -1);
            fail("Test 2: IndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected. 
        } 
        try { 
            writer.append(testString, 1, 0);
            fail("Test 3: IndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected. 
        } 
        try { 
            writer.append(testString, 1, testString.length() + 1);
            fail("Test 4: IndexOutOfBoundsException expected.");
        } catch (IndexOutOfBoundsException e) {
            // Expected. 
        } 
 
        writer.append(testString, 1, 3);
        writer.flush();
        assertEquals("Test 5: Appending failed;",
                testString.substring(1, 3), writer.toString());
        writer.close();
    } 
 
    protected void setUp() { 
        cw = new CharArrayWriter();
Stop searching for code, let great code find you!  Add Codota to your java IDE