@Override public User get() { Iterable<User> users = Iterables.concat(client.getAccountApi().listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(creds.get().identity); User currentUser = null; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } return currentUser; } }
@Override public User get() { Iterable<User> users = Iterables.concat(client.getAccountClient().listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(creds.get().identity); User currentUser = null; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } return currentUser; } }
@Override public User get() { Iterable<User> users = Iterables.concat(client.getAccountClient().listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(creds.get().identity); User currentUser = null; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } return currentUser; } }
private static User verifyCurrentUserIsOfType(String identity, AccountClient accountClient, Account.Type type) { Iterable<User> users = Iterables.concat(accountClient.listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(identity); User currentUser; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } if (currentUser.getAccountType() != type) { Logger.getAnonymousLogger().warning( String.format("Expecting an user with type %s. Got: %s", type.toString(), currentUser.toString())); } return currentUser; }
@Test public void testMatchApiKey() { assertTrue(apiKeyEquals("random-text").apply( User.builder().id("random-id").apiKey("random-text").build() )); assertFalse(apiKeyEquals("something-different").apply( User.builder().id("random-id").apiKey("random-text").build() )); }
private static User verifyCurrentUserIsOfType(String identity, AccountApi accountClient, Account.Type type) { Iterable<User> users = Iterables.concat(accountClient.listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(identity); User currentUser; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } if (currentUser.getAccountType() != type) { Logger.getAnonymousLogger().warning( String.format("Expecting an user with type %s. Got: %s", type.toString(), currentUser.toString())); } return currentUser; }
@Test public void testMatchApiKey() { assertTrue(apiKeyEquals("random-text").apply( User.builder().id("random-id").apiKey("random-text").build() )); assertFalse(apiKeyEquals("something-different").apply( User.builder().id("random-id").apiKey("random-text").build() )); }