### Question:
UsbFileOutputStream extends OutputStream { @Override public void write(int oneByte) throws IOException { ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[] {(byte) oneByte}); file.write(currentByteOffset, byteBuffer); currentByteOffset++; } UsbFileOutputStream(@NonNull UsbFile file); @Override void write(int oneByte); @Override void close(); @Override void flush(); @Override void write(byte[] buffer); @Override void write(byte[] buffer, int offset, int count);  }### Answer:
@Test public void writeInt() throws Exception { OutputStream os = new UsbFileOutputStream(file); os.write(0); verify(file).write(longCaptor.capture(), byteBufferCaptor.capture()); assertEquals(0, longCaptor.getValue().longValue()); assertNotNull(byteBufferCaptor.getValue()); os.write(new byte[1]); verify(file, times(2)).write(longCaptor.capture(), byteBufferCaptor.capture()); assertEquals(1, longCaptor.getValue().longValue()); assertNotNull(byteBufferCaptor.getValue()); }
@Test public void write() throws Exception { OutputStream os = new UsbFileOutputStream(file); os.write(new byte[20]); verify(file).write(longCaptor.capture(), byteBufferCaptor.capture()); assertEquals(0, longCaptor.getValue().longValue()); assertEquals(20, byteBufferCaptor.getValue().remaining()); os.write(new byte[20]); verify(file, times(2)).write(longCaptor.capture(), byteBufferCaptor.capture()); assertEquals(20, longCaptor.getValue().longValue()); assertEquals(20, byteBufferCaptor.getValue().remaining()); }
@Test public void writeOffset() throws Exception { OutputStream os = new UsbFileOutputStream(file); os.write(new byte[20], 10, 5); verify(file).write(longCaptor.capture(), byteBufferCaptor.capture()); assertEquals(0, longCaptor.getValue().longValue()); assertEquals(10, byteBufferCaptor.getValue().position()); assertEquals(5, byteBufferCaptor.getValue().remaining()); os.write(new byte[20], 5, 10); verify(file, times(2)).write(longCaptor.capture(), byteBufferCaptor.capture()); assertEquals(5, longCaptor.getValue().longValue()); assertEquals(5, byteBufferCaptor.getValue().position()); assertEquals(10, byteBufferCaptor.getValue().remaining()); }