@Test
public void shouldHandleInet() throws Exception {

  Codec<InetAddress> inetCodec = mapper.codecFor(primitive(INET));
  assertThat(inetCodec).isSameAs(mapper.inet);
  InetAddress ipv6 =
      InetAddress.getByAddress(
          new byte[] {127, 0, 0, 1, 127, 0, 0, 2, 127, 0, 0, 3, 122, 127, 125, 124});
  InetAddress ipv4 = InetAddress.getByAddress(new byte[] {127, 0, 0, 1});
  // ipv4
  encodeAndDecode(inetCodec, ipv4, "0x7f000001");
  // ipv6
  encodeAndDecode(inetCodec, ipv6, "0x7f0000017f0000027f0000037a7f7d7c");
  encodeAndDecode(inetCodec, null, null);
  encodeObjectAndDecode(inetCodec, ipv4, "0x7f000001", ipv4);
  encodeObjectAndDecode(inetCodec, "127.0.0.1", "0x7f000001", ipv4);
  encodeObjectAndDecode(inetCodec, "notanip.>>>", null, null);
  encodeObjectAndDecode(inetCodec, null, null, null);
  encodeObjectAndDecode(inetCodec, Optional.of(12), null, null);
  try {
    // invalid number of bytes.
    inetCodec.decode(Bytes.fromHexString("0x7f00000102"));
    fail("Shouldn't have been able to decode 5 byte address");
  } catch (InvalidTypeException e) {
    assertThat(e.getCause()).isInstanceOf(UnknownHostException.class);
  }
}