PreferenceScopeValidatorImpl implements PreferenceScopeValidator { @Override public void validate(final PreferenceScope scope) throws InvalidPreferenceScopeException { if (scope == null) { throw new InvalidPreferenceScopeException("A root scope must not be null."); } for (PreferenceScope currentScope = scope; currentScope != null; currentScope = currentScope.childScope()) { final String type = currentScope.type(); final String key = currentScope.key(); if (scopeTypes.typeRequiresKey(type) && isEmpty(key)) { throw new InvalidPreferenceScopeException("The type " + type + " must be associated with a non empty key."); } } if (!scopeResolutionStrategy.getInfo().order().contains(scope)) { throw new InvalidPreferenceScopeException("This scope is not defined in the scope hierarchy."); } } protected  PreferenceScopeValidatorImpl(); @Inject  PreferenceScopeValidatorImpl(@Customizable final PreferenceScopeTypes scopeTypes,
                                        @Customizable final PreferenceScopeResolutionStrategy scopeResolutionStrategy); @Override void validate(final PreferenceScope scope);  }
@Test(expected = InvalidPreferenceScopeException.class) public void validateNullScopeTest() { validator.validate(null); }
@Test(expected = InvalidPreferenceScopeException.class) public void validateScopeWithInvalidTypeTest() { validator.validate(new PreferenceScopeImpl("invalidType", null, null)); }
@Test(expected = InvalidPreferenceScopeException.class) public void validateScopeWithTypeThatRequiresKeyWithoutKeyTest() { validator.validate(new PreferenceScopeImpl(DefaultScopes.COMPONENT.type(), null, null)); }
@Test(expected = InvalidPreferenceScopeException.class) public void validateScopeWithValidScopeButNotInTheOrderTest() { validator.validate(new PreferenceScopeImpl(DefaultScopes.USER.type(), null, null)); }
@Test public void validateValidScopeTest() { validator.validate(userEntireApplicationScope); }