PcpString implements PcpOffset,MmvWritable { @Override public void writeToMmv(ByteBuffer byteBuffer) { byteBuffer.position(offset); byte[] bytes = initialValue.getBytes(PCP_CHARSET); Preconditions.checkArgument(bytes.length < STRING_BLOCK_LENGTH); byteBuffer.put(bytes); byteBuffer.put((byte) 0); } PcpString(String value); @Override int getOffset(); @Override void setOffset(int offset); @Override int byteSize(); @Override void writeToMmv(ByteBuffer byteBuffer);  }
@Test public void shouldWriteToTheByteBufferWithANullTerminatingString() { ByteBuffer byteBuffer = mock(ByteBuffer.class); PcpString pcpString = new PcpString(MY_STRING); pcpString.writeToMmv(byteBuffer); InOrder inOrder = Mockito.inOrder(byteBuffer); inOrder.verify(byteBuffer).put(MY_STRING.getBytes(CHARSET)); inOrder.verify(byteBuffer).put((byte) 0); }