@Test( expected = ConfigStoreException.class ) public void testLoadException() throws Exception { Preferences pref = mock( Preferences.class ); Configuration config = mock( Configuration.class ); doReturn( pref ).when( base ).node( TEST_PATH ); doThrow( BackingStoreException.class ).when( pref ).keys(); storage.load( TEST_PATH, config ); }
public Configuration load( final String configPath, final Configuration defaults ) throws ConfigStoreException { if ( ConfigFactory.isValidPath( configPath ) == false ) { throw new IllegalArgumentException( "The give path is not valid." ); } try { final Properties props = new Properties(); final Preferences pref = base.node( configPath ); final String[] keysArray = pref.keys(); for ( int i = 0; i < keysArray.length; i++ ) { final String key = keysArray[i]; final String value = pref.get( key, null ); if ( value != null ) { props.setProperty( key, value ); } } final ModifiableConfiguration config = new HierarchicalConfiguration( defaults ); final Iterator keys = props.keySet().iterator(); while ( keys.hasNext() ) { final String key = (String) keys.next(); config.setConfigProperty( key, props.getProperty( key ) ); } return config; } catch ( BackingStoreException be ) { throw new ConfigStoreException( "Failed to load config" + configPath, be ); } }
Java14ConfigStorage implements ConfigStorage { public Configuration load( final String configPath, final Configuration defaults ) throws ConfigStoreException { if ( ConfigFactory.isValidPath( configPath ) == false ) { throw new IllegalArgumentException( "The give path is not valid." ); } try { final Properties props = new Properties(); final Preferences pref = base.node( configPath ); final String[] keysArray = pref.keys(); for ( int i = 0; i < keysArray.length; i++ ) { final String key = keysArray[i]; final String value = pref.get( key, null ); if ( value != null ) { props.setProperty( key, value ); } } final ModifiableConfiguration config = new HierarchicalConfiguration( defaults ); final Iterator keys = props.keySet().iterator(); while ( keys.hasNext() ) { final String key = (String) keys.next(); config.setConfigProperty( key, props.getProperty( key ) ); } return config; } catch ( BackingStoreException be ) { throw new ConfigStoreException( "Failed to load config" + configPath, be ); } } }
Java14ConfigStorage implements ConfigStorage { public Configuration load( final String configPath, final Configuration defaults ) throws ConfigStoreException { if ( ConfigFactory.isValidPath( configPath ) == false ) { throw new IllegalArgumentException( "The give path is not valid." ); } try { final Properties props = new Properties(); final Preferences pref = base.node( configPath ); final String[] keysArray = pref.keys(); for ( int i = 0; i < keysArray.length; i++ ) { final String key = keysArray[i]; final String value = pref.get( key, null ); if ( value != null ) { props.setProperty( key, value ); } } final ModifiableConfiguration config = new HierarchicalConfiguration( defaults ); final Iterator keys = props.keySet().iterator(); while ( keys.hasNext() ) { final String key = (String) keys.next(); config.setConfigProperty( key, props.getProperty( key ) ); } return config; } catch ( BackingStoreException be ) { throw new ConfigStoreException( "Failed to load config" + configPath, be ); } } Java14ConfigStorage( final Preferences base ); }
Java14ConfigStorage implements ConfigStorage { public Configuration load( final String configPath, final Configuration defaults ) throws ConfigStoreException { if ( ConfigFactory.isValidPath( configPath ) == false ) { throw new IllegalArgumentException( "The give path is not valid." ); } try { final Properties props = new Properties(); final Preferences pref = base.node( configPath ); final String[] keysArray = pref.keys(); for ( int i = 0; i < keysArray.length; i++ ) { final String key = keysArray[i]; final String value = pref.get( key, null ); if ( value != null ) { props.setProperty( key, value ); } } final ModifiableConfiguration config = new HierarchicalConfiguration( defaults ); final Iterator keys = props.keySet().iterator(); while ( keys.hasNext() ) { final String key = (String) keys.next(); config.setConfigProperty( key, props.getProperty( key ) ); } return config; } catch ( BackingStoreException be ) { throw new ConfigStoreException( "Failed to load config" + configPath, be ); } } Java14ConfigStorage( final Preferences base ); void store( final String configPath, final Configuration config ); Configuration load( final String configPath, final Configuration defaults ); boolean isAvailable( final String configPath ); }
Java14ConfigStorage implements ConfigStorage { public Configuration load( final String configPath, final Configuration defaults ) throws ConfigStoreException { if ( ConfigFactory.isValidPath( configPath ) == false ) { throw new IllegalArgumentException( "The give path is not valid." ); } try { final Properties props = new Properties(); final Preferences pref = base.node( configPath ); final String[] keysArray = pref.keys(); for ( int i = 0; i < keysArray.length; i++ ) { final String key = keysArray[i]; final String value = pref.get( key, null ); if ( value != null ) { props.setProperty( key, value ); } } final ModifiableConfiguration config = new HierarchicalConfiguration( defaults ); final Iterator keys = props.keySet().iterator(); while ( keys.hasNext() ) { final String key = (String) keys.next(); config.setConfigProperty( key, props.getProperty( key ) ); } return config; } catch ( BackingStoreException be ) { throw new ConfigStoreException( "Failed to load config" + configPath, be ); } } Java14ConfigStorage( final Preferences base ); void store( final String configPath, final Configuration config ); Configuration load( final String configPath, final Configuration defaults ); boolean isAvailable( final String configPath );  }