public static Set<String> validateScopes(String scopeClaimName, Collection<String> scopes) throws ValidateException {
        if (scopes == null)
            throw new ValidateException(String.format("%s value must be non-null", scopeClaimName));

        Set<String> copy = new HashSet<>();

        for (String scope : scopes) {
            scope = validateString(scopeClaimName, scope);

            if (copy.contains(scope))
                throw new ValidateException(String.format("%s value must not contain duplicates - %s already present", scopeClaimName, scope));

            copy.add(scope);
        }

        return Collections.unmodifiableSet(copy);
    }
@Test
    public void testValidateScopes() {
        Set<String> scopes = ClaimValidationUtils.validateScopes("scope", Arrays.asList("  a  ", "    b    "));

        assertEquals(2, scopes.size());
        assertTrue(scopes.contains("a"));
        assertTrue(scopes.contains("b"));
    }