Index: BufferedWriterTest.java =================================================================== --- BufferedWriterTest.java (revision 430789) +++ BufferedWriterTest.java (working copy) @@ -110,7 +110,47 @@ fail("Exception during write test"); } } - + + void writeString(String buf, int offset, int count, boolean exception) throws IOException { + bw = new BufferedWriter(new Support_StringWriter(), 500); + try { + bw.write(buf, offset, count); + assertFalse("Expected StringIndexOutOfBoundsException", exception); + } catch (StringIndexOutOfBoundsException e) { + assertTrue("Unexpected StringIndexOutOfBoundsException", exception); + } + bw.flush(); + bw.close(); + } + + void writeChar(char[] buf, int offset, int count, boolean exception) throws IOException { + bw = new BufferedWriter(new Support_StringWriter(), 500); + try { + bw.write(buf, offset, count); + assertFalse("Expected IndexOutOfBoundsException", exception); + } catch (IndexOutOfBoundsException e) { + assertTrue("Unexpected IndexOutOfBoundsException", exception); + } + bw.flush(); + bw.close(); + } + + public void test_write_bad() throws IOException { + String s = "abcdef"; + writeString(s, 1, -1, false); + writeString(s,-1, 1, true); + writeString(s,-1, -1, false); + writeString(s, 7, 1, true); + writeString(s, 3, 4, true); + + char[] c = new char[] {'a', 'b', 'c', 'd', 'e'}; + writeChar(c, 1, -1, true); + writeChar(c,-1, 1, true); + writeChar(c,-1, -1, true); + writeChar(c, 7, 1, true); + writeChar(c, 3, 4, true); + } + /** * @tests java.io.BufferedWriter#write(int) */