Java Code Examples for org.apache.commons.configuration2.builder.BasicConfigurationBuilder#reset()

The following examples show how to use org.apache.commons.configuration2.builder.BasicConfigurationBuilder#reset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a reset of the builder. The configuration instance should be
 * created anew.
 */
@Test
public void testResetBuilder() throws ConfigurationException
{
    final Map<String, Object> attrs = new HashMap<>();
    final BasicConfigurationBuilder<? extends HierarchicalConfiguration<ImmutableNode>> defBuilder =
            prepareSubBuilderTest(attrs);
    final CombinedConfiguration cc = builder.getConfiguration();
    final ConfigurationBuilder<? extends Configuration> subBuilder =
            builder.getNamedBuilder(BUILDER_NAME);
    defBuilder.reset();
    final CombinedConfiguration cc2 = builder.getConfiguration();
    assertNotSame("No new configuration instance", cc, cc2);
    final ConfigurationBuilder<? extends Configuration> subBuilder2 =
            builder.getNamedBuilder(BUILDER_NAME);
    assertNotSame("No new sub builder instance", subBuilder, subBuilder2);
}
 
Example 2
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that change listeners registered at sub builders are removed on a
 * reset.
 */
@Test
public void testRemoveSubBuilderListener() throws ConfigurationException
{
    final Map<String, Object> attrs = new HashMap<>();
    prepareSubBuilderTest(attrs);
    builder.getConfiguration();
    final BasicConfigurationBuilder<?> subBuilder =
            (BasicConfigurationBuilder<?>) builder
                    .getNamedBuilder(BUILDER_NAME);
    builder.reset();
    prepareSubBuilderTest(attrs);
    final CombinedConfiguration cc = builder.getConfiguration();
    final BasicConfigurationBuilder<?> subBuilder2 =
            (BasicConfigurationBuilder<?>) builder
                    .getNamedBuilder(BUILDER_NAME);
    assertNotSame("Got the same sub builder", subBuilder, subBuilder2);
    subBuilder.reset();
    assertSame("Configuration was reset", cc, builder.getConfiguration());
}
 
Example 3
Source File: TestCombinedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether a reset of one of the sub builders causes the combined
 * configuration to be re-created.
 */
@Test
public void testReactOnSubBuilderChange() throws ConfigurationException
{
    final Map<String, Object> attrs = new HashMap<>();
    prepareSubBuilderTest(attrs);
    final CombinedConfiguration cc = builder.getConfiguration();
    final BasicConfigurationBuilder<?> subBuilder =
            (BasicConfigurationBuilder<?>) builder
                    .getNamedBuilder(BUILDER_NAME);
    subBuilder.reset();
    assertNotSame("Configuration not newly created", cc,
            builder.getConfiguration());
}