DeconstructedPrincipal { public static DeconstructedPrincipal valueOf(String principal, @Nullable String defaultRealm) { if (principal == null) { throw new IllegalArgumentException("The principal may not be null"); } Matcher matcher = PATTERN_PRINCIPAL.matcher(principal); if (matcher.matches()) { String primary = matcher.group(1); String instance = matcher.group(2); String realm = matcher.group(3); if ((realm == null) || realm.isEmpty()) { realm = defaultRealm; } return new DeconstructedPrincipal(primary, instance, realm); } else { throw new IllegalArgumentException(String.format("Invalid principal value: %s", principal)); } } protected  DeconstructedPrincipal(String primary, String instance, String realm); static DeconstructedPrincipal valueOf(String principal, @Nullable String defaultRealm); String getPrimary(); String getInstance(); String getRealm(); String getPrincipalName(); String getNormalizedPrincipal();  }
@Test(expected = IllegalArgumentException.class) public void testNullPrincipal() throws Exception { DeconstructedPrincipal.valueOf(null, null); }
@Test(expected = IllegalArgumentException.class) public void testEmptyPrincipal() throws Exception { DeconstructedPrincipal.valueOf("", null); }
@Test(expected = IllegalArgumentException.class) public void testInvalidPrincipal() throws Exception { DeconstructedPrincipal.valueOf("/invalid", null); }
@Test(expected = IllegalArgumentException.class) public void testInstance() throws Exception { DeconstructedPrincipal.valueOf("/instance", "REALM"); }
@Test(expected = IllegalArgumentException.class) public void testInstanceRealm() throws Exception { DeconstructedPrincipal.valueOf("/instance@MYREALM", "REALM"); }