From 45aa17238604d13a83420e9c538f3a8c00ec46bf Mon Sep 17 00:00:00 2001
From: Kusal Kithul-Godage
- * TODO: The lazy instantiation of XmlConfigurationProvider should be refactored to be elsewhere. The behavior described above seems unintuitive. + * TODO: The lazy instantiation of StrutsDefaultConfigurationProvider should be refactored to be elsewhere. The behavior described above seems unintuitive. *
* * @return the list of registered ConfigurationProvider objects @@ -137,6 +137,13 @@ public void addContainerProvider(ContainerProvider provider) { } } + public void removeContainerProvider(ContainerProvider provider) { + if (containerProviders.remove(provider)) { + clearContainerProvider(provider); + providersChanged = true; + } + } + public void clearContainerProviders() { for (ContainerProvider containerProvider : containerProviders) { clearContainerProvider(containerProvider); diff --git a/core/src/test/java/com/opensymphony/xwork2/config/ConfigurationManagerTest.java b/core/src/test/java/com/opensymphony/xwork2/config/ConfigurationManagerTest.java index bb54ad5653..a37ac6b345 100644 --- a/core/src/test/java/com/opensymphony/xwork2/config/ConfigurationManagerTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/config/ConfigurationManagerTest.java @@ -30,6 +30,9 @@ import java.util.Properties; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + /** * ConfigurationManagerTest @@ -147,6 +150,19 @@ public void register(ContainerBuilder builder, LocatableProperties props) throws assertTrue(state.isDestroyed2); } + public void testRemoveConfigurationProvider() throws Exception { + ConfigurationProvider configProvider1 = mock(ConfigurationProvider.class); + ConfigurationProvider configProvider2 = mock(ConfigurationProvider.class); + configurationManager.addContainerProvider(configProvider1); + configurationManager.addContainerProvider(configProvider2); + + configurationManager.removeContainerProvider(configProvider1); + + verify(configProvider1).destroy(); + assertFalse(configurationManager.getContainerProviders().contains(configProvider1)); + assertTrue(configurationManager.getContainerProviders().contains(configProvider2)); + } + public void testClearConfigurationProviders() throws Exception { configProviderMock.expect("destroy"); configurationManager.clearContainerProviders();