### Question:
XsuaaToken extends AbstractToken implements AccessToken { @Override public Principal getPrincipal() { String principalName; switch (getGrantType()) { case CLIENT_CREDENTIALS: case CLIENT_X509: principalName = String.format(UNIQUE_CLIENT_NAME_FORMAT, getClaimAsString(CLIENT_ID)); break; default: principalName = getUniquePrincipalName(getClaimAsString(ORIGIN), getClaimAsString(USER_NAME)); break; } return createPrincipalByName(principalName); } XsuaaToken(@Nonnull DecodedJwt decodedJwt);  XsuaaToken(@Nonnull String accessToken); XsuaaToken withScopeConverter(@Nullable ScopeConverter converter); @Override Set<String> getScopes(); @Override Principal getPrincipal(); @Override Service getService(); @Override boolean hasScope(String scope); @Override boolean hasLocalScope(@Nonnull String scope); @Override GrantType getGrantType(); @Nullable String getSubdomain(); @Nullable String getSubaccountId(); @Override String getZoneId();  }### Answer:
@Test public void getUserPrincipal() { assertThat(userToken.getClaimAsString(TokenClaims.USER_NAME)).isEqualTo("testUser"); assertThat(userToken.getClaimAsString(TokenClaims.XSUAA.ORIGIN)).isEqualTo("userIdp"); assertThat(userToken.getPrincipal()).isNotNull(); assertThat(userToken.getPrincipal().getName()).isEqualTo("user/userIdp/testUser"); }
@Test public void getClientPrincipal() { assertThat(clientCredentialsToken.getClaimAsString(TokenClaims.XSUAA.CLIENT_ID)).isEqualTo("sap_osb"); assertThat(clientCredentialsToken.getPrincipal()).isNotNull(); assertThat(clientCredentialsToken.getPrincipal().getName()).isEqualTo("client/sap_osb"); }
@Test public void getPrincipalShouldBeEqualForSameUser() throws IOException { Token userToken2 = new XsuaaToken(IOUtils.resourceToString("/xsuaaUserAccessTokenRSA256.txt", UTF_8)); assertThat(userToken.getPrincipal()).isEqualTo(userToken2.getPrincipal()); }