CustomizableByteArrayOutputStream extends OutputStream { @Synchronized public int size() { return this.count; } CustomizableByteArrayOutputStream(int initialCapacity, int maxArraySize, double fillFactorToCopy); @Override @Synchronized void write(int byteToWrite); @Override @Synchronized void write(byte[] buffer, int off, int len); @Synchronized byte[] getBufferOrCopy(); @Synchronized int size(); @Override void close(); @Synchronized void reset();  }
@Test void size() { tested.write(10); tested.write(20); tested.write(30); assertThat(tested.size()).isEqualTo(3); assertThat(tested.buffer.length).isEqualTo(4); }