-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #518 from elandau/bugfix/typo
Improve initializing and reseting listeners in the static bridge
- Loading branch information
Showing
2 changed files
with
125 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...s1-bridge/src/test/java/com/netflix/archaius/bridge/StaticBridgeAddConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.netflix.archaius.bridge; | ||
|
||
import org.apache.commons.configuration.event.ConfigurationEvent; | ||
import org.apache.commons.configuration.event.ConfigurationListener; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Guice; | ||
import com.netflix.archaius.api.config.SettableConfig; | ||
import com.netflix.archaius.api.inject.RuntimeLayer; | ||
import com.netflix.archaius.guice.ArchaiusModule; | ||
import com.netflix.config.ConfigurationManager; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class StaticBridgeAddConfigurationTest { | ||
private static ConfigurationListener listener = Mockito.mock(ConfigurationListener.class); | ||
|
||
public static class Foo { | ||
public static void addListenerBeforeBridgeInitialization() { | ||
ConfigurationManager.getConfigInstance().addConfigurationListener(listener); | ||
} | ||
} | ||
|
||
@Inject | ||
@RuntimeLayer | ||
SettableConfig settableConfig; | ||
|
||
@Test | ||
public void listenerAddedToStaticBeforeStaticInjection() { | ||
Guice.createInjector(new ArchaiusModule(), new StaticArchaiusBridgeModule(), new AbstractModule() { | ||
@Override | ||
protected void configure() { | ||
Foo.addListenerBeforeBridgeInitialization(); | ||
this.requestInjection(StaticBridgeAddConfigurationTest.this); | ||
} | ||
}); | ||
|
||
// Verify that the listener is called | ||
Mockito.verify(listener, Mockito.never()).configurationChanged(Mockito.isA(ConfigurationEvent.class)); | ||
settableConfig.setProperty("foo", "bar"); | ||
Mockito.verify(listener, Mockito.times(2)).configurationChanged(Mockito.isA(ConfigurationEvent.class)); | ||
|
||
// Listener no longer invoked after reset | ||
StaticArchaiusBridgeModule.resetStaticBridges(); | ||
settableConfig.setProperty("bar", "baz"); | ||
Mockito.verify(listener, Mockito.times(2)).configurationChanged(Mockito.isA(ConfigurationEvent.class)); | ||
|
||
} | ||
} |