### Question:
HttpUtil { public static String formatHostnameForHttp(InetSocketAddress addr) { String hostString = NetUtil.getHostname(addr); if (NetUtil.isValidIpV6Address(hostString)) { if (!addr.isUnresolved()) { hostString = NetUtil.toAddressString(addr.getAddress()); } return '[' + hostString + ']'; } return hostString; } private  HttpUtil(); static boolean isOriginForm(URI uri); static boolean isAsteriskForm(URI uri); static boolean isKeepAlive(HttpMessage message); static void setKeepAlive(HttpMessage message, boolean keepAlive); static void setKeepAlive(HttpHeaders h, HttpVersion httpVersion, boolean keepAlive); static long getContentLength(HttpMessage message); static long getContentLength(HttpMessage message, long defaultValue); static int getContentLength(HttpMessage message, int defaultValue); static void setContentLength(HttpMessage message, long length); static boolean isContentLengthSet(HttpMessage m); static boolean is100ContinueExpected(HttpMessage message); static void set100ContinueExpected(HttpMessage message, boolean expected); static boolean isTransferEncodingChunked(HttpMessage message); static void setTransferEncodingChunked(HttpMessage m, boolean chunked); static Charset getCharset(HttpMessage message); static Charset getCharset(CharSequence contentTypeValue); static Charset getCharset(HttpMessage message, Charset defaultCharset); static Charset getCharset(CharSequence contentTypeValue, Charset defaultCharset); @Deprecated static CharSequence getCharsetAsString(HttpMessage message); static CharSequence getCharsetAsSequence(HttpMessage message); static CharSequence getCharsetAsSequence(CharSequence contentTypeValue); static CharSequence getMimeType(HttpMessage message); static CharSequence getMimeType(CharSequence contentTypeValue); static String formatHostnameForHttp(InetSocketAddress addr);  }### Answer:
@Test public void testFormatHostnameForHttpFromResolvedAddressWithHostname() throws Exception { InetSocketAddress socketAddress = new InetSocketAddress(InetAddress.getByName("localhost"), 8080); assertEquals("localhost", HttpUtil.formatHostnameForHttp(socketAddress)); }
@Test public void testFormatHostnameForHttpFromUnesolvedAddressWithHostname() { InetSocketAddress socketAddress = InetSocketAddress.createUnresolved("localhost", 80); assertEquals("localhost", HttpUtil.formatHostnameForHttp(socketAddress)); }
@Test public void testIpv6() throws Exception { InetSocketAddress socketAddress = new InetSocketAddress(InetAddress.getByName("::1"), 8080); assertEquals("[::1]", HttpUtil.formatHostnameForHttp(socketAddress)); }
@Test public void testIpv6Unresolved() { InetSocketAddress socketAddress = InetSocketAddress.createUnresolved("::1", 8080); assertEquals("[::1]", HttpUtil.formatHostnameForHttp(socketAddress)); }
@Test public void testIpv4() throws Exception { InetSocketAddress socketAddress = new InetSocketAddress(InetAddress.getByName("10.0.0.1"), 8080); assertEquals("10.0.0.1", HttpUtil.formatHostnameForHttp(socketAddress)); }
@Test public void testIpv4Unresolved() { InetSocketAddress socketAddress = InetSocketAddress.createUnresolved("10.0.0.1", 8080); assertEquals("10.0.0.1", HttpUtil.formatHostnameForHttp(socketAddress)); }