Part { public void writeTo(OutputStream out, ByteBuffer buf) throws IOException { if (getLength() > 0) { if (this.part instanceof byte[]) { byte[] bytes = (byte[]) this.part; out.write(bytes, 0, bytes.length); } else if (this.part instanceof StoredObject) { StoredObject so = (StoredObject) this.part; ByteBuffer sobb = so.createDirectByteBuffer(); if (sobb != null) { HeapDataOutputStream.writeByteBufferToStream(out, buf, sobb); } else { int bytesToSend = so.getDataSize(); long addr = so.getAddressForReadingData(0, bytesToSend); while (bytesToSend > 0) { if (buf.remaining() == 0) { HeapDataOutputStream.flushStream(out, buf); } buf.put(AddressableMemoryManager.readByte(addr)); addr++; bytesToSend--; } } } else { HeapDataOutputStream hdos = (HeapDataOutputStream) this.part; try { hdos.sendTo(out, buf); } finally { hdos.rewind(); } } } }  void init(byte[] v, byte tc); void clear(); boolean isNull(); boolean isObject(); boolean isBytes(); void setPartState(byte[] b, boolean isObject); void setPartState(HeapDataOutputStream os, boolean isObject); void setPartState(StoredObject so, boolean isObject); byte getTypeCode(); int getLength(); String getString(); String getCachedString(); void setByte(byte b); byte getByte(); int getInt(); static int decodeInt(byte[] bytes, int offset); void setInt(int v); static void encodeInt(int v, byte[] bytes); static void encodeInt(int v, byte[] bytes, int offset); void setLong(long v); long getLong(); byte[] getSerializedForm(); Object getObject(boolean unzip); Object getObject(); Object getStringOrObject(); void writeTo(OutputStream out, ByteBuffer buf); void writeTo(ByteBuffer buf); void writeTo(SocketChannel sc, ByteBuffer buf); @Override String toString(); void setVersion(KnownVersion clientVersion);  }
@Test public void shouldBeMockable() throws Exception { Part mockPart = mock(Part.class); OutputStream mockOutputStream = mock(OutputStream.class); ByteBuffer mockByteBuffer = mock(ByteBuffer.class); mockPart.writeTo(mockOutputStream, mockByteBuffer); verify(mockPart, times(1)).writeTo(mockOutputStream, mockByteBuffer); }