### Question:
NetUtils { public static String formatInetAddr(InetSocketAddress addr) { InetAddress ia = addr.getAddress(); if (ia == null) { return String.format("%s:%s", addr.getHostString(), addr.getPort()); } if (ia instanceof Inet6Address) { return String.format("[%s]:%s", ia.getHostAddress(), addr.getPort()); } else { return String.format("%s:%s", ia.getHostAddress(), addr.getPort()); } }  static String formatInetAddr(InetSocketAddress addr); static String[] getIPV6HostAndPort(String hostPort);  }### Answer:
@Test public void testFormatInetAddrGoodIpv6Ext() { InetSocketAddress isa = new InetSocketAddress("2600::", port); assertEquals(v6ext, NetUtils.formatInetAddr(isa)); }
@Test public void testFormatInetAddrGoodHostname() { InetSocketAddress isa = new InetSocketAddress("localhost", 1234); assertThat(NetUtils.formatInetAddr(isa), anyOf(equalTo(v4local), equalTo(v6local))); }
@Test public void testFormatAddrUnresolved() { InetSocketAddress isa = InetSocketAddress.createUnresolved("doesnt.exist.com", 1234); assertEquals("doesnt.exist.com:1234", NetUtils.formatInetAddr(isa)); }
@Test public void testFormatInetAddrGoodIpv4() { InetSocketAddress isa = new InetSocketAddress(v4addr, port); assertEquals("127.0.0.1:1234", NetUtils.formatInetAddr(isa)); }
@Test public void testFormatInetAddrGoodIpv6Local() { InetSocketAddress isa = new InetSocketAddress("::1", port); assertEquals(v6local, NetUtils.formatInetAddr(isa)); }