Util { public static void validatePort(int port) throws UserErrorException { if (port < 0 || port > 0xFFFF) { throw new UserErrorException("port out of range: " + port); } } 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 validatePort_Negative() throws Exception { try { Util.validatePort(-1); fail("should throw exception"); } catch(UserErrorException e) { String msg = e.getMessage(); assertTrue(msg.contains("port out of range")); } }
@Test public void validatePort_Zero() throws Exception { Util.validatePort(0); }
@Test public void validatePort_Max() throws Exception { Util.validatePort(65535); }
@Test public void validatePort_BeyondMax() throws Exception { try { Util.validatePort(65536); fail("should throw exception"); } catch(UserErrorException e) { String msg = e.getMessage(); assertTrue(msg.contains("port out of range")); } }