@Test public void shouldWatchForFileChanges() { writeConfigLines("my.dataSource.jdbcUrl=jdbc:datamastery:example", "my.dataSource.jdbcUsername=sa", "my.dataSource.jdbcPassword="); observer.onConfigChange(new DummyDataSourceConfigListener( "my.dataSource", dataSource -> this.dataSource = dataSource )); assertThat(dataSource).isEqualToComparingFieldByField(new DummyDataSource( "jdbc:datamastery:example", "sa", "" )); dataSource = null; writeConfigLine("otherConfig=something"); assertThat(dataSource).isNull(); writeConfigLines("my.dataSource.jdbcUrl=jdbc:datamastery:UPDATED", "my.dataSource.jdbcUsername=sa", "my.dataSource.jdbcPassword="); assertThat(dataSource).isEqualToComparingFieldByField(new DummyDataSource( "jdbc:datamastery:UPDATED", "sa", "" )); }
public ConfigObserver onConfigChange(ConfigListener listener) { this.listeners.add(listener); notifyListener(listener, null, new ConfigMap(currentConfiguration)); return this; }
ConfigObserver { public ConfigObserver onConfigChange(ConfigListener listener) { this.listeners.add(listener); notifyListener(listener, null, new ConfigMap(currentConfiguration)); return this; } }
ConfigObserver { public ConfigObserver onConfigChange(ConfigListener listener) { this.listeners.add(listener); notifyListener(listener, null, new ConfigMap(currentConfiguration)); return this; } ConfigObserver(String applicationName);  ConfigObserver(File configDirectory, String applicationName);  ConfigObserver(File configDirectory, String applicationName, List<String> profiles);  ConfigObserver(ConfigLoader configLoader); }
ConfigObserver { public ConfigObserver onConfigChange(ConfigListener listener) { this.listeners.add(listener); notifyListener(listener, null, new ConfigMap(currentConfiguration)); return this; } ConfigObserver(String applicationName);  ConfigObserver(File configDirectory, String applicationName);  ConfigObserver(File configDirectory, String applicationName, List<String> profiles);  ConfigObserver(ConfigLoader configLoader); ConfigObserver onConfigChange(ConfigListener listener); ConfigObserver onSingleConfigValue(String key, Function<String, T> transformer, T defaultValue, ConfigValueListener<T> listener); ConfigObserver onStringValue(String key, String defaultValue, ConfigValueListener<String> listener); ConfigObserver onIntValue(String key, int defaultValue, ConfigValueListener<Integer> listener); ConfigObserver onLongValue(String key, long defaultValue, ConfigValueListener<Long> listener); ConfigObserver onInetSocketAddress(String key, int defaultPort, ConfigValueListener<InetSocketAddress> listener); ConfigObserver onInetSocketAddress(String key, InetSocketAddress defaultAddress, ConfigValueListener<InetSocketAddress> listener); ConfigObserver onDurationValue(String key, Duration defaultValue, ConfigValueListener<Duration> listener); ConfigObserver onStringListValue(String key, String defaultValue, ConfigValueListener<List<String>> listener); ConfigObserver onPrefixedValue(String prefix, ConfigValueListener<Map<String, String>> listener); ConfigObserver onPrefixedValue(String prefix, ConfigListener.Transformer<T> transformer, ConfigValueListener<T> listener); ConfigObserver onPrefixedOptionalValue(String prefix, ConfigListener.Transformer<T> transformer, ConfigValueListener<Optional<T>> listener); ConfigObserver onPrefixedOptionalValue(String prefix, ConfigValueListener<Optional<Map<String, String>>> listener); void updateConfiguration(Map<String, String> newConfiguration); }
ConfigObserver { public ConfigObserver onConfigChange(ConfigListener listener) { this.listeners.add(listener); notifyListener(listener, null, new ConfigMap(currentConfiguration)); return this; } ConfigObserver(String applicationName);  ConfigObserver(File configDirectory, String applicationName);  ConfigObserver(File configDirectory, String applicationName, List<String> profiles);  ConfigObserver(ConfigLoader configLoader); ConfigObserver onConfigChange(ConfigListener listener); ConfigObserver onSingleConfigValue(String key, Function<String, T> transformer, T defaultValue, ConfigValueListener<T> listener); ConfigObserver onStringValue(String key, String defaultValue, ConfigValueListener<String> listener); ConfigObserver onIntValue(String key, int defaultValue, ConfigValueListener<Integer> listener); ConfigObserver onLongValue(String key, long defaultValue, ConfigValueListener<Long> listener); ConfigObserver onInetSocketAddress(String key, int defaultPort, ConfigValueListener<InetSocketAddress> listener); ConfigObserver onInetSocketAddress(String key, InetSocketAddress defaultAddress, ConfigValueListener<InetSocketAddress> listener); ConfigObserver onDurationValue(String key, Duration defaultValue, ConfigValueListener<Duration> listener); ConfigObserver onStringListValue(String key, String defaultValue, ConfigValueListener<List<String>> listener); ConfigObserver onPrefixedValue(String prefix, ConfigValueListener<Map<String, String>> listener); ConfigObserver onPrefixedValue(String prefix, ConfigListener.Transformer<T> transformer, ConfigValueListener<T> listener); ConfigObserver onPrefixedOptionalValue(String prefix, ConfigListener.Transformer<T> transformer, ConfigValueListener<Optional<T>> listener); ConfigObserver onPrefixedOptionalValue(String prefix, ConfigValueListener<Optional<Map<String, String>>> listener); void updateConfiguration(Map<String, String> newConfiguration);  }