TransferProgressFileOutputStream extends FileOutputStream { @Override public void write(int b) throws IOException { super.write(b); this.transferProgress.notify(new byte[]{(byte) b}, 1); } TransferProgressFileOutputStream(File file, TransferProgress transferProgress); @Override void write(int b); @Override void write(byte b[]); @Override void write(byte b[], int off, int len);  }
@Test public void write() throws IOException { this.outputStream.write(1); assertArrayEquals(new byte[]{(byte) 1}, this.transferProgress.getBuffer()); assertEquals(1, this.transferProgress.getLength()); }
@Test public void readByteArray() throws IOException { byte[] buffer = new byte[SIZE]; Arrays.fill(buffer, (byte) 1); this.outputStream.write(buffer); assertArrayEquals(buffer, this.transferProgress.getBuffer()); assertEquals(SIZE, this.transferProgress.getLength()); }
@Test public void readyByteArrayLength() throws IOException { byte[] buffer = new byte[SIZE]; Arrays.fill(buffer, (byte) 1); this.outputStream.write(buffer, 0, SIZE); assertArrayEquals(buffer, this.transferProgress.getBuffer()); assertEquals(SIZE, this.transferProgress.getLength()); }
@Test public void readyByteArrayOffsetLength() throws IOException { byte[] buffer = new byte[BIG_SIZE]; Arrays.fill(buffer, START_POSITION, END_POSITION, (byte) 1); this.outputStream.write(buffer, START_POSITION, SIZE); byte[] expected = new byte[SIZE]; System.arraycopy(buffer, START_POSITION, expected, 0, SIZE); assertArrayEquals(expected, this.transferProgress.getBuffer()); assertEquals(SIZE, this.transferProgress.getLength()); }