### Question:
NetUtils { public static boolean isValidAddress(String address) { return ADDRESS_PATTERN.matcher(address).matches(); }  static int getRandomPort(); static int getAvailablePort(); static int getAvailablePort(int port); static boolean isInvalidPort(int port); static boolean isValidAddress(String address); static boolean isLocalHost(String host); static boolean isAnyHost(String host); static boolean isInvalidLocalHost(String host); static boolean isValidLocalHost(String host); static InetSocketAddress getLocalSocketAddress(String host, int port); static String getLocalHost(); static String filterLocalHost(String host); static InetAddress getLocalAddress(); static String getHostName(String address); static String getIpByHost(String hostName); static String toAddressString(InetSocketAddress address); static InetSocketAddress toAddress(String address); static String toURL(String protocol, String host, int port, String path);  }### Answer:
@Test public void testValidAddress() throws Exception { assertTrue(NetUtils.isValidAddress("10.20.130.230:20880")); assertFalse(NetUtils.isValidAddress("10.20.130.230")); assertFalse(NetUtils.isValidAddress("10.20.130.230:666666")); }
@Test public void testIsValidAddress() throws Exception { assertFalse(NetUtils.isValidAddress((InetAddress) null)); InetAddress address = mock(InetAddress.class); when(address.isLoopbackAddress()).thenReturn(true); assertFalse(NetUtils.isValidAddress(address)); address = mock(InetAddress.class); when(address.getHostAddress()).thenReturn("localhost"); assertFalse(NetUtils.isValidAddress(address)); address = mock(InetAddress.class); when(address.getHostAddress()).thenReturn("0.0.0.0"); assertFalse(NetUtils.isValidAddress(address)); address = mock(InetAddress.class); when(address.getHostAddress()).thenReturn("127.0.0.1"); assertFalse(NetUtils.isValidAddress(address)); address = mock(InetAddress.class); when(address.getHostAddress()).thenReturn("1.2.3.4"); assertTrue(NetUtils.isValidAddress(address)); }