StringToByteBufferAdapter implements TypeAdapter<String, ByteBuffer> { @Override public ByteBuffer adapt(String source) { if (source == null) { return null; } else { return ByteBuffer.wrap(source.getBytes(StringUtils.UTF8)); } }  @Override ByteBuffer adapt(String source);  }
@Test public void nullString_ReturnsNullByteBuffer() { assertNull(adapter.adapt(null)); }
@Test public void emptyString_ReturnsEmptyByteBuffer() throws IOException { ByteBuffer byteBuffer = adapter.adapt(""); assertEquals(0, byteBuffer.remaining()); }
@Test public void nonEmptyString_ReturnsNonEmptyByteBuffer() throws IOException { String source = "foo"; ByteBuffer byteBuffer = adapter.adapt(source); assertEquals(new String(byteBuffer.array()), source); }