DefaultPreferenceScopeResolver implements PreferenceScopeResolver { @Override public PreferenceScope resolve(final String... scopeTypes) { if (scopeTypes != null && scopeTypes.length >= 1 && scopeTypes.length <= 2) { if (scopeTypes.length == 2) { return getScopeFromOrder(scopeTypes); } String scopeType = scopeTypes[0]; if (scopeType.equals(DefaultScopes.USER.type())) { return getScopeFromOrder(DefaultScopes.USER.type(), DefaultScopes.ENTIRE_APPLICATION.type()); } else if (scopeType.equals(DefaultScopes.ALL_USERS.type())) { return getScopeFromOrder(DefaultScopes.ALL_USERS.type(), DefaultScopes.ENTIRE_APPLICATION.type()); } else if (scopeType.equals(DefaultScopes.COMPONENT.type())) { return getScopeFromOrder(DefaultScopes.ALL_USERS.type(), DefaultScopes.COMPONENT.type()); } else if (scopeType.equals(DefaultScopes.ENTIRE_APPLICATION.type())) { return getScopeFromOrder(DefaultScopes.ALL_USERS.type(), DefaultScopes.ENTIRE_APPLICATION.type()); } } throw new InvalidPreferenceScopeException("The passed scope types are invalid."); } DefaultPreferenceScopeResolver(@MapsTo("order") final List<PreferenceScope> order); @Override PreferenceScope resolve(final String... scopeTypes);  }
@Test public void resolveValidScopesTest() { assertEquals(userEntireApplicationScope, scopeResolver.resolve(userScopeType)); assertEquals(allUsersComponentScope, scopeResolver.resolve(componentScopeType)); assertEquals(allUsersEntireApplicationScope, scopeResolver.resolve(allUsersScopeType)); assertEquals(allUsersEntireApplicationScope, scopeResolver.resolve(entireApplicationScopeType)); assertEquals(userComponentScope, scopeResolver.resolve(userScopeType, componentScopeType)); assertEquals(userEntireApplicationScope, scopeResolver.resolve(userScopeType, entireApplicationScopeType)); assertEquals(allUsersComponentScope, scopeResolver.resolve(allUsersScopeType, componentScopeType)); assertEquals(allUsersEntireApplicationScope, scopeResolver.resolve(allUsersScopeType, entireApplicationScopeType)); }
@Test(expected = InvalidPreferenceScopeException.class) public void tryResolveWithInvalidScopeTypeTest() { scopeResolver.resolve("invalidScopeType"); }
@Test(expected = InvalidPreferenceScopeException.class) public void tryResolveWithNoScopeTypesTest() { scopeResolver.resolve(); }
@Test(expected = InvalidPreferenceScopeException.class) public void tryResolveWithThreeScopeTypesTest() { scopeResolver.resolve(userScopeType, componentScopeType, entireApplicationScopeType); }