예제 #1
0
  @Test(expected = InvalidSettingException.class)
  public void shouldNotAllowSettingInvalidValues() {
    Config config = new Config(new HashMap<String, String>(), MySettingsWithDefaults.class);

    Map<String, String> params = config.getParams();
    params.put(MySettingsWithDefaults.boolSetting.name(), "asd");

    config.applyChanges(params);

    fail("Expected validation to fail.");
  }
예제 #2
0
  @Test
  public void shouldNotNotifyChangeListenerWhenNothingChanged() {
    // Given
    Config config = new Config(stringMap("setting", "old"), MyMigratingSettings.class);
    ChangeCaptureListener listener = new ChangeCaptureListener();
    config.addConfigurationChangeListener(listener);

    // When
    config.applyChanges(stringMap("setting", "old")); // nothing really changed here

    // Then
    assertThat(listener.lastChangeSet, nullValue());
  }
예제 #3
0
  @Test
  public void shouldNotifyChangeListenersWhenNewSettingsAreApplied() {
    // Given
    Config config = new Config(stringMap("setting", "old"), MyMigratingSettings.class);
    ChangeCaptureListener listener = new ChangeCaptureListener();
    config.addConfigurationChangeListener(listener);

    // When
    config.applyChanges(stringMap("setting", "new"));

    // Then
    assertThat(listener.lastChangeSet, is(setOf(new ConfigurationChange("setting", "old", "new"))));
  }