### Question:
MessageFormatWriteSet implements MessageWriteSet { @Override public long writeTo(Write writeChannel) throws StoreException { ReadableByteChannel readableByteChannel = Channels.newChannel(streamToWrite); long sizeWritten = 0; for (MessageInfo info : streamInfo) { writeChannel.appendFrom(readableByteChannel, info.getSize()); sizeWritten += info.getSize(); } return sizeWritten; } MessageFormatWriteSet(InputStream streamToWrite, List<MessageInfo> streamInfo, boolean materializeStream); @Override long writeTo(Write writeChannel); @Override List<MessageInfo> getMessageSetInfo();  }### Answer:
@Test public void writeSetTest() throws IOException, StoreException { byte[] buf = new byte[2000]; MessageInfo info1 = new MessageInfo(new MockId("id1"), 1000, 123, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), System.currentTimeMillis() + TestUtils.RANDOM.nextInt()); MessageInfo info2 = new MessageInfo(new MockId("id2"), 1000, 123, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), System.currentTimeMillis() + TestUtils.RANDOM.nextInt()); List<MessageInfo> infoList = new ArrayList<MessageInfo>(); infoList.add(info1); infoList.add(info2); ByteBufferInputStream byteBufferInputStream = new ByteBufferInputStream(ByteBuffer.wrap(buf)); MessageFormatWriteSet set = new MessageFormatWriteSet(byteBufferInputStream, infoList, false); MockWrite write = new MockWrite(2000); long written = set.writeTo(write); Assert.assertEquals(written, 2000); Assert.assertEquals(write.getBuffer().limit(), 2000); Assert.assertArrayEquals(write.getBuffer().array(), buf); }