DefaultPreferenceScopeTypes implements PreferenceScopeTypes { @Override public String getDefaultKeyFor(final String type) throws InvalidPreferenceScopeException { validateType(type); final DefaultKey defaultKey = defaultKeyByType.get(type); if (defaultKey == null) { throw new InvalidPreferenceScopeException("The type " + type + " does not have a default key."); } return defaultKey.get(); } protected  DefaultPreferenceScopeTypes(); @Inject  DefaultPreferenceScopeTypes(final UsernameProvider usernameProvider); @Override boolean typeRequiresKey(final String type); @Override String getDefaultKeyFor(final String type);  }
@Test public void defaultKeysForTypesTest() { assertEquals(DefaultScopes.ALL_USERS.type(), defaultPreferenceScopeTypes.getDefaultKeyFor(DefaultScopes.ALL_USERS.type())); assertEquals(DefaultScopes.ENTIRE_APPLICATION.type(), defaultPreferenceScopeTypes.getDefaultKeyFor(DefaultScopes.ENTIRE_APPLICATION.type())); assertEquals("admin", defaultPreferenceScopeTypes.getDefaultKeyFor(DefaultScopes.USER.type())); }
@Test(expected = InvalidPreferenceScopeException.class) public void defaultKeysForTypesThatDoNotHaveDefaultKeysTest() { defaultPreferenceScopeTypes.getDefaultKeyFor(DefaultScopes.COMPONENT.type()); }