Validate { public static boolean domainName(String name) { if (name == null || name.isEmpty()) { return false; } Matcher matcher = domainPattern.matcher(name); return matcher.matches(); }  static boolean principalName(String name); static boolean domainName(String name);  }
@Test public void testDomainNameValidationInvalid() { assertFalse(Validate.domainName("domain$sub")); assertFalse(Validate.domainName("coretech:domain")); assertFalse(Validate.domainName("")); assertFalse(Validate.domainName(null)); }
@Test public void testDomainNameValidationValid() { assertTrue(Validate.domainName("55")); assertTrue(Validate.domainName("3com.gov")); assertTrue(Validate.domainName("domain")); assertTrue(Validate.domainName("domain.sub.sub")); assertTrue(Validate.domainName("domain_")); assertTrue(Validate.domainName("_")); assertTrue(Validate.domainName("_test._")); assertTrue(Validate.domainName("sub1_sub2")); assertTrue(Validate.domainName("sub1_sub2_sub3")); assertTrue(Validate.domainName("sub1_sub2.sub3_sub4")); assertTrue(Validate.domainName("sub1_sub2_.sub3_sub4_")); assertTrue(Validate.domainName("sub1_sub2_.sub3_sub4_-")); assertTrue(Validate.domainName("domain-part")); assertTrue(Validate.domainName("com-test.gov")); }