Validate { public static boolean principalName(String name) { if (name == null || name.isEmpty()) { return false; } Matcher matcher = principalPattern.matcher(name); return matcher.matches(); }  static boolean principalName(String name); static boolean domainName(String name);  }
@Test public void testPrincipalNameValidationInvalid() { assertFalse(Validate.principalName("user:john%doe")); assertFalse(Validate.principalName("user.user:john.doe.")); assertFalse(Validate.principalName("user.user.:john.doe")); assertFalse(Validate.principalName(".user:doe")); assertFalse(Validate.principalName(".doe")); assertFalse(Validate.principalName(":doe")); assertFalse(Validate.principalName("doe:")); assertFalse(Validate.principalName("::doe")); assertFalse(Validate.principalName("doe::")); assertFalse(Validate.principalName("user:john:doe")); assertFalse(Validate.principalName(null)); assertFalse(Validate.principalName("")); }
@Test public void testPrincipalNameValidationValid() { assertTrue(Validate.principalName("user:doe")); assertTrue(Validate.principalName("user:doe")); assertTrue(Validate.principalName("user:john.doe")); assertTrue(Validate.principalName("user.user:doe")); assertTrue(Validate.principalName("user.user:john.doe")); assertTrue(Validate.principalName("user:john_doe")); assertTrue(Validate.principalName("john-doe")); assertTrue(Validate.principalName("user:john-doe")); }