Util { public static String inetAddressToString(InetAddress a) { if (a == null) { return "null"; } String s = a.getClass().getSimpleName(); s += " "; s += a; if (a.isMulticastAddress()) { s += " (MULTICAST)"; } return s; } private  Util(); static byte[] addressToBytes(String address); static boolean identical(byte[] b, byte[] b2); static void validatePort(int port); static InetSocketAddress computeLocalEndpoint(
            NetworkInterface ni, InetAddress localAddress, Integer localPort, InetAddress address, Integer port); static boolean isIPv4(InetAddress a); static boolean isIPv6(InetAddress a); static String inetAddressToString(InetAddress a); static void displayInfo(); static void dumpState(Configuration c, DatagramSocket s, DatagramPacket p); static String truncate(byte[] payload, int length); static final Pattern IPv4_FORMAT; }
@Test public void inetAddressToString_null() throws Exception { String s = Util.inetAddressToString(null); assertEquals("null", s); }
@Test public void inetAddressToString_IPv4() throws Exception { InetAddress a = InetAddress.getByAddress(new byte[] {127, 7, 7, 7}); String s = Util.inetAddressToString(a); assertEquals("Inet4Address /127.7.7.7", s); }
@Test public void inetAddressToString_IPv4_Multicast() throws Exception { InetAddress a = InetAddress.getByAddress(new byte[] {(byte)225, 5, 5, 5}); String s = Util.inetAddressToString(a); assertEquals("Inet4Address /225.5.5.5 (MULTICAST)", s); }
@Test public void inetAddressToString_IPv6() throws Exception { InetAddress a = InetAddress.getByAddress(new byte[] {127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7}); String s = Util.inetAddressToString(a); assertEquals("Inet6Address /7f00:0:0:0:0:0:7:707", s); }