Skip to content

Commit

Permalink
Merge pull request #711 from Codegass/refactoring-testBasicReplacement
Browse files Browse the repository at this point in the history
Refactor ConfigManagerTest to Include Assertions for Automated Validation
  • Loading branch information
rgallardo-netflix authored Mar 26, 2024
2 parents 55a05d6 + 27732ff commit 084a29d
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
package com.netflix.archaius;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.concurrent.atomic.AtomicReference;

import com.netflix.archaius.api.Property;
import com.netflix.archaius.api.PropertyFactory;
import com.netflix.archaius.config.DefaultCompositeConfig;
Expand All @@ -39,19 +43,26 @@ public void testBasicReplacement() throws ConfigException {
.put("region", "us-east")
.put("c", 123)
.build()));


PropertyFactory factory = DefaultPropertyFactory.from(config);

Property<String> prop = factory.getProperty("abc").asString("defaultValue");


// Use an AtomicReference to capture the property value change
AtomicReference<String> capturedValue = new AtomicReference<>("");
prop.addListener(new DefaultPropertyListener<String>() {
@Override
public void onChange(String next) {
System.out.println("Configuration changed : " + next);
capturedValue.set(next);
}
});


// Set property which should trigger the listener
dyn.setProperty("abc", "${c}");

// Assert that the capturedValue was updated correctly
assertEquals("123", capturedValue.get(), "Configuration change did not occur as expected");

}
}

0 comments on commit 084a29d

Please sign in to comment.