EmbeddedOAuthAPI implements OAuthAPI { @Override public OAuthToken getToken(String oauthProvider) throws NotFoundException, UnauthorizedException, ServerException { OAuthAuthenticator provider = getAuthenticator(oauthProvider); final Subject subject = EnvironmentContext.getCurrent().getSubject(); try { OAuthToken token = provider.getToken(subject.getUserId()); if (token == null) { token = provider.getToken(subject.getUserName()); } if (token != null) { return token; } throw new UnauthorizedException( "OAuth token for user " + subject.getUserId() + " was not found"); } catch (IOException e) { throw new ServerException(e.getLocalizedMessage(), e); } }  @Override Response authenticate(
      UriInfo uriInfo,
      String oauthProvider,
      List<String> scopes,
      String redirectAfterLogin,
      HttpServletRequest request); @Override Response callback(UriInfo uriInfo, List<String> errorValues); @Override Set<OAuthAuthenticatorDescriptor> getRegisteredAuthenticators(UriInfo uriInfo); @Override OAuthToken getToken(String oauthProvider); @Override void invalidateToken(String oauthProvider);  }
@Test( expectedExceptions = NotFoundException.class, expectedExceptionsMessageRegExp = "Unsupported OAuth provider unknown") public void shouldThrowExceptionIfNoSuchProviderFound() throws Exception { embeddedOAuthAPI.getToken("unknown"); }