### Question:
InetAddressValidator implements ConstraintValidator<InetAddress, CharSequence> { @Override public boolean isValid(CharSequence value, ConstraintValidatorContext context) { if (!IPV4_PATTERN.matcher(value).matches()) { return false; } return true; }  @Override boolean isValid(CharSequence value, ConstraintValidatorContext context); @Override void initialize(InetAddress parameters);  }### Answer:
@Test public void testInetAddressesFromTheWild() { assertTrue("www.apache.org IP should be valid", validator.isValid("140.211.11.130", null)); assertTrue("www.l.google.com IP should be valid", validator.isValid("72.14.253.103", null)); assertTrue("fsf.org IP should be valid", validator.isValid("199.232.41.5", null)); assertTrue("appscs.ign.com IP should be valid", validator.isValid("216.35.123.87", null)); }
@Test public void testInetAddressesByClass() { assertTrue("class A IP should be valid", validator.isValid("24.25.231.12", null)); assertFalse("illegal class A IP should be invalid", validator.isValid("2.41.32.324", null)); assertTrue("class B IP should be valid", validator.isValid("135.14.44.12", null)); assertFalse("illegal class B IP should be invalid", validator.isValid("154.123.441.123", null)); assertTrue("class C IP should be valid", validator.isValid("213.25.224.32", null)); assertFalse("illegal class C IP should be invalid", validator.isValid("201.543.23.11", null)); assertTrue("class D IP should be valid", validator.isValid("229.35.159.6", null)); assertFalse("illegal class D IP should be invalid", validator.isValid("231.54.11.987", null)); assertTrue("class E IP should be valid", validator.isValid("248.85.24.92", null)); assertFalse("illegal class E IP should be invalid", validator.isValid("250.21.323.48", null)); }
@Test public void testReservedInetAddresses() { assertTrue("localhost IP should be valid", validator.isValid("127.0.0.1", null)); assertTrue("broadcast IP should be valid", validator.isValid("255.255.255.255", null)); }
@Test public void testBrokenInetAddresses() { assertFalse("IP with characters should be invalid", validator.isValid("124.14.32.abc", null)); assertFalse("IP with three groups should be invalid", validator.isValid("23.64.12", null)); assertFalse("IP with five groups should be invalid", validator.isValid("26.34.23.77.234", null)); }