PreferenceScopeFactoryImpl implements PreferenceScopeFactory { @Override public PreferenceScope createScope(final String type) throws InvalidPreferenceScopeException { return createScopeWithoutKey(type, null); } protected  PreferenceScopeFactoryImpl(); @Inject  PreferenceScopeFactoryImpl(@Customizable final PreferenceScopeTypes scopeTypes); @Override PreferenceScope createScope(final String type); @Override PreferenceScope createScope(final String type,
                                       final PreferenceScope childScope); @Override PreferenceScope createScope(final String type,
                                       final String key); @Override PreferenceScope createScope(final String type,
                                       final String key,
                                       final PreferenceScope childScope); @Override PreferenceScope createScope(final PreferenceScope... scopes); @Override PreferenceScope cloneScope(final PreferenceScope scope);  }
@Test public void createScopeByTypeWithDefaultKeyTest() { PreferenceScope userScope = scopeFactory.createScope(DefaultScopes.USER.type()); assertEquals(DefaultScopes.USER.type(), userScope.type()); assertEquals("admin", userScope.key()); }
@Test(expected = InvalidPreferenceScopeException.class) public void createScopeByTypeWithoutDefaultKeyTest() { scopeFactory.createScope(DefaultScopes.COMPONENT.type()); }
@Test public void createScopeByTypeAndKeyWithoutDefaultKeyTest() { PreferenceScope componentScope = scopeFactory.createScope(DefaultScopes.COMPONENT.type(), "my-component"); assertEquals(DefaultScopes.COMPONENT.type(), componentScope.type()); assertEquals("my-component", componentScope.key()); }
@Test(expected = InvalidPreferenceScopeException.class) public void createScopeByTypeAndKeyWithDefaultKeyTest() { scopeFactory.createScope(DefaultScopes.USER.type(), "user"); }
@Test public void createScopeByTypeAndChildScopeWithDefaultKeyTest() { PreferenceScope userScope = scopeFactory.createScope(DefaultScopes.USER.type(), genericScope); assertEquals(DefaultScopes.USER.type(), userScope.type()); assertEquals("admin", userScope.key()); }
@Test(expected = InvalidPreferenceScopeException.class) public void createScopeByTypeAndChildScopeWithoutDefaultKeyTest() { scopeFactory.createScope(DefaultScopes.COMPONENT.type(), genericScope); }
@Test public void createScopeByTypeKeyAndChildScopeWithoutDefaultKeyTest() { PreferenceScope componentScope = scopeFactory.createScope(DefaultScopes.COMPONENT.type(), "my-component", genericScope); assertEquals(DefaultScopes.COMPONENT.type(), componentScope.type()); assertEquals("my-component", componentScope.key()); }
@Test(expected = InvalidPreferenceScopeException.class) public void createScopeByTypeKeyAndChildScopeWithDefaultKeyTest() { scopeFactory.createScope(DefaultScopes.USER.type(), "user", genericScope); }
@Test public void createHierarchicalScopeByScopesTest() { PreferenceScope scope = scopeFactory.createScope(userScope, entireApplicationScope); assertEquals(DefaultScopes.USER.type(), scope.type()); assertEquals(userScopeKey, scope.key()); final PreferenceScope childScope = scope.childScope(); assertEquals(DefaultScopes.ENTIRE_APPLICATION.type(), childScope.type()); assertEquals(DefaultScopes.ENTIRE_APPLICATION.type(), childScope.key()); assertNull(childScope.childScope()); }