### Question:
XsuaaToken extends AbstractToken implements AccessToken { @Nullable public String getSubaccountId() { return Optional.ofNullable(getAttributeFromClaimAsString(EXTERNAL_ATTRIBUTE, EXTERNAL_ATTRIBUTE_SUBACCOUNTID)) .orElse(getClaimAsString(ZONE_ID)); } 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 getSubaccountId() { XsuaaToken userTokenWithSubaccountId = Mockito.spy(userToken); when(userTokenWithSubaccountId.getClaimAsJsonObject(TokenClaims.XSUAA.EXTERNAL_ATTRIBUTE)) .thenReturn(new DefaultJsonObject("{\"subaccountid\": \"abc123\"}")); assertThat(userTokenWithSubaccountId.getSubaccountId()).isEqualTo("abc123"); }
@Test public void getSubaccountId_noSubaccountId_fallsBackToZoneId() { assertThat(clientCredentialsToken.getSubaccountId()).isEqualTo("uaa"); }
@Test public void getSubaccountId_noSubaccountIdAndNoFallback_isNull() { assertThat(userToken.getSubaccountId()).isNull(); }