@Test public void testValidateConfigurationOption() throws Exception { final ConfigurationOption<Boolean> configurationOption = ConfigurationOption.booleanOption() .key("foo") .addValidator((value) -> { if (!value) { throw new IllegalArgumentException("Validation failed"); } }) .buildWithDefault(true); final ConfigurationOptionProvider optionProvider = TestConfigurationOptionProvider.of(configurationOption); final SimpleSource configurationSource = new SimpleSource("test"); final ConfigurationRegistry config = ConfigurationRegistry.builder() .addOptionProvider(optionProvider) .addConfigSource(configurationSource) .build(); try { config.save("foo", "false", "test"); fail(); } catch (IllegalArgumentException e) { assertEquals("Validation failed", e.getMessage()); } }
private ConfigurationOption<?> validateConfigurationOption(String key, String value) throws IllegalArgumentException { final ConfigurationOption configurationOption = getConfigurationOptionByKey(key); if (configurationOption != null) { configurationOption.assertValid(value); return configurationOption; } else { throw new IllegalArgumentException("Config key '" + key + "' does not exist."); } }
ConfigurationRegistry implements Closeable { private ConfigurationOption<?> validateConfigurationOption(String key, String value) throws IllegalArgumentException { final ConfigurationOption configurationOption = getConfigurationOptionByKey(key); if (configurationOption != null) { configurationOption.assertValid(value); return configurationOption; } else { throw new IllegalArgumentException("Config key '" + key + "' does not exist."); } } }
ConfigurationRegistry implements Closeable { private ConfigurationOption<?> validateConfigurationOption(String key, String value) throws IllegalArgumentException { final ConfigurationOption configurationOption = getConfigurationOptionByKey(key); if (configurationOption != null) { configurationOption.assertValid(value); return configurationOption; } else { throw new IllegalArgumentException("Config key '" + key + "' does not exist."); } } @Deprecated  ConfigurationRegistry(Iterable<? extends ConfigurationOptionProvider> optionProviders,
								 List<ConfigurationSource> configSources); @Deprecated  ConfigurationRegistry(Iterable<? extends ConfigurationOptionProvider> optionProviders,
								 List<ConfigurationSource> configSources, boolean failOnMissingRequiredValues); }
ConfigurationRegistry implements Closeable { private ConfigurationOption<?> validateConfigurationOption(String key, String value) throws IllegalArgumentException { final ConfigurationOption configurationOption = getConfigurationOptionByKey(key); if (configurationOption != null) { configurationOption.assertValid(value); return configurationOption; } else { throw new IllegalArgumentException("Config key '" + key + "' does not exist."); } } @Deprecated  ConfigurationRegistry(Iterable<? extends ConfigurationOptionProvider> optionProviders,
								 List<ConfigurationSource> configSources); @Deprecated  ConfigurationRegistry(Iterable<? extends ConfigurationOptionProvider> optionProviders,
								 List<ConfigurationSource> configSources, boolean failOnMissingRequiredValues); static Builder builder(); T getConfig(Class<T> configClass); Collection<ConfigurationOptionProvider> getConfigurationOptionProviders(); Map<String, List<ConfigurationOption<?>>> getConfigurationOptionsByCategory(); Map<String, ConfigurationOption<?>> getConfigurationOptionsByKey(); Map<String, Boolean> getNamesOfConfigurationSources(); ConfigurationOption<?> getConfigurationOptionByKey(String key); void scheduleReloadAtRate(final long rate, TimeUnit timeUnit); void reload(String key); void reloadAllConfigurationOptions(); void reloadDynamicConfigurationOptions(); void addConfigurationSource(ConfigurationSource configurationSource); void addConfigurationSourceAfter(ConfigurationSource configurationSource, Class<? extends ConfigurationSource> addAfter); void addConfigurationSource(ConfigurationSource configurationSource, boolean firstPrio); void save(String key, String value, String configurationSourceName); String getString(String key); @Override void close(); }
ConfigurationRegistry implements Closeable { private ConfigurationOption<?> validateConfigurationOption(String key, String value) throws IllegalArgumentException { final ConfigurationOption configurationOption = getConfigurationOptionByKey(key); if (configurationOption != null) { configurationOption.assertValid(value); return configurationOption; } else { throw new IllegalArgumentException("Config key '" + key + "' does not exist."); } } @Deprecated  ConfigurationRegistry(Iterable<? extends ConfigurationOptionProvider> optionProviders,
								 List<ConfigurationSource> configSources); @Deprecated  ConfigurationRegistry(Iterable<? extends ConfigurationOptionProvider> optionProviders,
								 List<ConfigurationSource> configSources, boolean failOnMissingRequiredValues); static Builder builder(); T getConfig(Class<T> configClass); Collection<ConfigurationOptionProvider> getConfigurationOptionProviders(); Map<String, List<ConfigurationOption<?>>> getConfigurationOptionsByCategory(); Map<String, ConfigurationOption<?>> getConfigurationOptionsByKey(); Map<String, Boolean> getNamesOfConfigurationSources(); ConfigurationOption<?> getConfigurationOptionByKey(String key); void scheduleReloadAtRate(final long rate, TimeUnit timeUnit); void reload(String key); void reloadAllConfigurationOptions(); void reloadDynamicConfigurationOptions(); void addConfigurationSource(ConfigurationSource configurationSource); void addConfigurationSourceAfter(ConfigurationSource configurationSource, Class<? extends ConfigurationSource> addAfter); void addConfigurationSource(ConfigurationSource configurationSource, boolean firstPrio); void save(String key, String value, String configurationSourceName); String getString(String key); @Override void close();  }