AuthUtils { @NonNull static Collection<Scope> stringToScopeCollection(@NonNull String scopesString) throws IllegalArgumentException { Set<Scope> scopeCollection = new HashSet<>(); if (scopesString.isEmpty()) { return scopeCollection; } String[] scopeStrings = scopesString.split(" "); for (String scopeName : scopeStrings) { try { scopeCollection.add(Scope.valueOf(scopeName.toUpperCase())); } catch (IllegalArgumentException e) { } } return scopeCollection; }  static boolean isRedirectUriRegistered(@NonNull Activity activity, @NonNull Uri uri); @NonNull static String scopeCollectionToString(@NonNull Collection<Scope> scopes); static String customScopeCollectionToString(@NonNull Collection<String> scopes); static String mergeScopeStrings(String... scopes);  }
@Test public void stringToScopeCollection_whenUnknownScopeInString_shouldReturnOnlyKnownScopes() { String scopeString = "profile custom"; List<Scope> scopes = new ArrayList<>(); scopes.addAll(AuthUtils.stringToScopeCollection(scopeString)); assertEquals(scopes.size(), 1); assertTrue(scopes.contains(Scope.PROFILE)); }
@Test public void stringToScopeCollection_whenOneScopeInString_shouldReturnCollectionOfOneScope() { String scopeString = "history"; List<Scope> scopes = new ArrayList<>(); scopes.addAll(AuthUtils.stringToScopeCollection(scopeString)); assertEquals(scopes.size(), 1); assertTrue(scopes.contains(Scope.HISTORY)); }
@Test public void stringToScopeCollection_whenCollectionOfStrings_shouldReturnCollectionOfScopes() { String scopeString = "profile history"; List<Scope> scopes = new ArrayList<>(); scopes.addAll(AuthUtils.stringToScopeCollection(scopeString)); assertTrue(scopes.contains(Scope.PROFILE)); assertTrue(scopes.contains(Scope.HISTORY)); }
@Test public void stringToScopeCollection_whenEmptyScopeString_shouldReturnEmptyScopeCollection() { String scopeString = ""; List<Scope> scopes = new ArrayList<>(); scopes.addAll(AuthUtils.stringToScopeCollection(scopeString)); assertEquals(scopes.size(), 0); }