### Question:
XSUserInfoAdapter implements XSUserInfo { @Override public String getToken(String namespace, String name) { if (!(getGrantType().equals(GrantType.CLIENT_CREDENTIALS.toString())) && hasAttributes() && isInForeignMode()) { throw new XSUserInfoException("The SecurityContext has been initialized with an access token of a\n" + "foreign OAuth Client Id and/or Identity Zone. Furthermore, the\n" + "access token contains attributes. Due to the fact that we want to\n" + "restrict attribute access to the application that provided the \n" + "attributes, the getToken function does not return a valid token"); } if (!namespace.equals(SYSTEM)) { throw new XSUserInfoException("Invalid namespace " + namespace); } if (name.equals(HDB)) { String token; if (accessToken.hasClaim(EXTERNAL_CONTEXT)) { token = accessToken.getAttributeFromClaimAsString(EXTERNAL_CONTEXT, HDB_NAMEDUSER_SAML); } else { token = accessToken.getClaimAsString(HDB_NAMEDUSER_SAML); } if (token == null) { token = accessToken.getTokenValue(); } return token; } else if (name.equals("JobScheduler")) { return accessToken.getTokenValue(); } else { throw new XSUserInfoException("Invalid name " + name + " for namespace " + namespace); } } XSUserInfoAdapter(Object accessToken);  XSUserInfoAdapter(AccessToken accessToken);   XSUserInfoAdapter(Object accessToken, OAuth2ServiceConfiguration configuration); @Override String getLogonName(); @Override String getGivenName(); @Override String getFamilyName(); @Override String getOrigin(); @Override String getIdentityZone(); @Override /** * "ext_attr": { "enhancer": "XSUAA", "subaccountid": "my-subaccount-1234" }, */ String getSubaccountId(); @Override String getZoneId(); @Override /** * "ext_attr": { "enhancer": "XSUAA", "zdn": "paas-subdomain" }, */ String getSubdomain(); @Override String getClientId(); @Override String getJsonValue(String attribute); @Override String getEmail(); @Override String getDBToken(); @Override String getHdbToken(); @Override String getAppToken(); @Override String getToken(String namespace, String name); @Override String[] getAttribute(String attributeName); @Override boolean hasAttributes(); @Override String[] getSystemAttribute(String attributeName); @Override boolean checkScope(String scope); @Override boolean checkLocalScope(String scope); @Override String getAdditionalAuthAttribute(String attributeName); @Override String getCloneServiceInstanceId(); @Override String getGrantType(); @Override boolean isInForeignMode(); @Override String requestTokenForClient(String clientId, String clientSecret, String baseUaaUrl); @Override String requestTokenForUser(String clientId, String clientSecret, String baseUaaUrl); @Override String requestToken(XSTokenRequest tokenRequest);  }### Answer:
@Test public void getToken_namespaceNotSystem_throwsException() { assertThatThrownBy(() -> cut.getToken("any", "any")).isInstanceOf(XSUserInfoException.class); }
@Test public void getToken_fallbackToTokenValue() throws XSUserInfoException { assertThat(cut.getToken(XSUserInfoAdapter.SYSTEM, XSUserInfoAdapter.HDB)).isEqualTo(token.getTokenValue()); }
@Test public void getToken_fromExternalContext() throws XSUserInfoException { XsuaaToken mockToken = createMockToken("token"); cut = new XSUserInfoAdapter(mockToken); assertThat(cut.getToken(XSUserInfoAdapter.SYSTEM, XSUserInfoAdapter.HDB)).isEqualTo("token"); }