UnsafeStringWriter extends Writer { @Override public void write(int c) { mBuffer.append((char) c); } UnsafeStringWriter();  UnsafeStringWriter(int size); @Override void write(int c); @Override void write(char[] cs); @Override void write(char[] cs, int off, int len); @Override void write(String str); @Override void write(String str, int off, int len); @Override Writer append(CharSequence csq); @Override Writer append(CharSequence csq, int start, int end); @Override Writer append(char c); @Override void close(); @Override void flush(); @Override String toString();  }
@Test(expected = IndexOutOfBoundsException.class) public void testWriteCharWithWrongLength() throws IOException { UnsafeStringWriter writer = new UnsafeStringWriter(); char[] chars = new char[0]; writer.write(chars, 0, 1); }
@Test(expected = IndexOutOfBoundsException.class) public void testWriteCharWithWrongCombineLength() throws IOException { UnsafeStringWriter writer = new UnsafeStringWriter(); char[] chars = new char[1]; writer.write(chars, 1, 1); }
@Test public void testWrite() { UnsafeStringWriter writer = new UnsafeStringWriter(); writer.write("a"); writer.write("abc", 1, 1); writer.write(99); writer.flush(); writer.close(); assertThat(writer.toString(), is("abc")); }
@Test public void testWriteCharWithWrongLength() throws IOException { Assertions.assertThrows(IndexOutOfBoundsException.class, () -> { UnsafeStringWriter writer = new UnsafeStringWriter(); char[] chars = new char[0]; writer.write(chars, 0, 1); }); }
@Test public void testWriteCharWithWrongCombineLength() throws IOException { Assertions.assertThrows(IndexOutOfBoundsException.class, () -> { UnsafeStringWriter writer = new UnsafeStringWriter(); char[] chars = new char[1]; writer.write(chars, 1, 1); }); }