import org.junit.Test;
import static org.junit.Assert.*;
import java.io.ByteArrayOutputStream;

public class ByteArrayOutputStreamTest {

    @Test
    public void initialState() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        assertEquals(0, out.size());
        assertArrayEquals(new byte[0], out.toByteArray());
        assertEquals("", out.toString());
    }

    @Test
    public void write() throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] bytes = {97, 98, 99}; // abc
        out.write(bytes);

        assertEquals(3, out.size());
        assertArrayEquals(bytes, out.toByteArray());
        assertEquals("abc", out.toString());
    }

    @Test
    public void toStringOrToByteArrayMoreThanOnce() throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] bytes = {97, 98, 99}; // abc
        out.write(bytes);

        assertArrayEquals(bytes, out.toByteArray());
        assertArrayEquals(bytes, out.toByteArray());
        assertEquals("abc", out.toString());
        assertEquals("abc", out.toString());
    }

    @Test
    public void reset() throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] bytes = {97, 98, 99}; // abc
        out.write(bytes);

        assertEquals(3, out.size());

        out.reset();

        assertEquals(0, out.size());
        assertArrayEquals(new byte[0], out.toByteArray());
        assertEquals("", out.toString());
    }

}


@@ -416,16 +416,24 @@
 id write
+AllBytes
 () throw
@@ -716,32 +716,707 @@
 ring());%0A    %7D%0A%0A
+    @Test%0A    public void writeSingleByte() throws Exception %7B%0A        ByteArrayOutputStream out = new ByteArrayOutputStream();%0A        out.write(97);%0A        out.write(98);%0A        out.write(99);%0A%0A        assertEquals(3, out.size());%0A        assertEquals(%22abc%22, out.toString());%0A    %7D%0A%0A    @Test%0A    public void writePartialBytes() throws Exception %7B%0A        ByteArrayOutputStream out = new ByteArrayOutputStream();%0A        byte%5B%5D bytes = %7B97, 98, 99, 100, 101, 102, 103%7D; // a b c d e f g%0A        out.write(bytes, 3, 3);%0A%0A        byte%5B%5D expected = %7B100, 101, 102%7D;%0A        assertArrayEquals(expected, out.toByteArray());%0A        assertEquals(%22def%22, out.toString());%0A    %7D%0A%0A
     @Test%0A    pu

Update usage of ByteArrayOutputStream.