This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-configuration.git
commit e98dd1c72c182742fe350191c45db685fb54d5df Author: Gary Gregory <[email protected]> AuthorDate: Mon May 11 12:33:41 2026 -0400 Sort members --- .../io/CombinedLocationStrategy.java | 22 ++++++------ .../configuration2/io/FileLocatorUtils.java | 40 +++++++++++----------- .../configuration2/TestXMLConfiguration.java | 10 +++--- .../configuration2/TestYAMLConfiguration.java | 12 +++---- .../io/TestProvidedURLLocationStrategy.java | 28 +++++++-------- 5 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/main/java/org/apache/commons/configuration2/io/CombinedLocationStrategy.java b/src/main/java/org/apache/commons/configuration2/io/CombinedLocationStrategy.java index c1eccf0c0..d0a99d6cc 100644 --- a/src/main/java/org/apache/commons/configuration2/io/CombinedLocationStrategy.java +++ b/src/main/java/org/apache/commons/configuration2/io/CombinedLocationStrategy.java @@ -64,17 +64,6 @@ public class CombinedLocationStrategy extends AbstractFileLocationStrategy { return new CombinedLocationStrategy(this); } - /** - * Sets the collection with sub strategies. - * - * @param subStrategies the collection with sub strategies. - * @return {@code this} instance. - */ - public Builder setSubStrategies(final Collection<FileLocationStrategy> subStrategies) { - this.subStrategies = subStrategies; - return asThis(); - } - /** * Propagates properties of the parent builder scheme and host to subStrategies. * @@ -97,6 +86,17 @@ public class CombinedLocationStrategy extends AbstractFileLocationStrategy { return asThis(); } + /** + * Sets the collection with sub strategies. + * + * @param subStrategies the collection with sub strategies. + * @return {@code this} instance. + */ + public Builder setSubStrategies(final Collection<FileLocationStrategy> subStrategies) { + this.subStrategies = subStrategies; + return asThis(); + } + } /** A collection with all sub strategies managed by this object. */ diff --git a/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java b/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java index e15ccf725..9fdfef8e0 100644 --- a/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java +++ b/src/main/java/org/apache/commons/configuration2/io/FileLocatorUtils.java @@ -417,26 +417,6 @@ public final class FileLocatorUtils { return locator != null ? ObjectUtils.getIfNull(locator.getLocationStrategy(), DEFAULT_LOCATION_STRATEGY) : DEFAULT_LOCATION_STRATEGY; } - /** - * Creates the default location strategy. This method creates a combined location strategy as described in the comment - * of the {@link #DEFAULT_LOCATION_STRATEGY} member field. - * - * @return the default {@code FileLocationStrategy} - * @since 2.15.0 - */ - public static FileLocationStrategy newDefaultLocationStrategy() { - // @formatter:off - return new CombinedLocationStrategy(Arrays.asList( - new ProvidedURLLocationStrategy(), - new FileSystemLocationStrategy(), - new AbsoluteNameLocationStrategy(), - new BasePathLocationStrategy(), - new HomeDirectoryLocationStrategy.Builder().setEvaluateBasePath(true).getUnchecked(), - new HomeDirectoryLocationStrategy.Builder().setEvaluateBasePath(false).getUnchecked(), - new ClasspathLocationStrategy())); - // @formatter:on - } - /** * Returns a flag whether all components of the given {@code FileLocator} describing the referenced file are defined. In * order to reference a file, it is not necessary that all components are filled in (for instance, the URL alone is @@ -503,6 +483,26 @@ public final class FileLocatorUtils { return url; } + /** + * Creates the default location strategy. This method creates a combined location strategy as described in the comment + * of the {@link #DEFAULT_LOCATION_STRATEGY} member field. + * + * @return the default {@code FileLocationStrategy} + * @since 2.15.0 + */ + public static FileLocationStrategy newDefaultLocationStrategy() { + // @formatter:off + return new CombinedLocationStrategy(Arrays.asList( + new ProvidedURLLocationStrategy(), + new FileSystemLocationStrategy(), + new AbsoluteNameLocationStrategy(), + new BasePathLocationStrategy(), + new HomeDirectoryLocationStrategy.Builder().setEvaluateBasePath(true).getUnchecked(), + new HomeDirectoryLocationStrategy.Builder().setEvaluateBasePath(false).getUnchecked(), + new ClasspathLocationStrategy())); + // @formatter:on + } + /** * Stores the specified {@code FileLocator} in the given map. With the {@link #fromMap(Map)} method a new * {@code FileLocator} with the same properties as the original one can be created. diff --git a/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java b/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java index c903574bc..efbbffa9e 100644 --- a/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java +++ b/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java @@ -1093,12 +1093,11 @@ public class TestXMLConfiguration { * Tests how to read from a DOM Node. */ @Test - void testReadDomElementManually() throws Exception { + void testReadDomElement() throws Exception { conf = new XMLConfiguration(); final Element domElement = buildDomElementFixture(); - conf.initFileLocator(FileLocatorUtils.fileLocator().create()); // Read from a DOM Element - conf.read(new ByteArrayInputStream(nodeToByteArray(domElement))); + conf.read(domElement); assertEquals("x", conf.getString("[@attr]")); } @@ -1106,11 +1105,12 @@ public class TestXMLConfiguration { * Tests how to read from a DOM Node. */ @Test - void testReadDomElement() throws Exception { + void testReadDomElementManually() throws Exception { conf = new XMLConfiguration(); final Element domElement = buildDomElementFixture(); + conf.initFileLocator(FileLocatorUtils.fileLocator().create()); // Read from a DOM Element - conf.read(domElement); + conf.read(new ByteArrayInputStream(nodeToByteArray(domElement))); assertEquals("x", conf.getString("[@attr]")); } diff --git a/src/test/java/org/apache/commons/configuration2/TestYAMLConfiguration.java b/src/test/java/org/apache/commons/configuration2/TestYAMLConfiguration.java index c4f2521c5..412b31647 100644 --- a/src/test/java/org/apache/commons/configuration2/TestYAMLConfiguration.java +++ b/src/test/java/org/apache/commons/configuration2/TestYAMLConfiguration.java @@ -76,18 +76,18 @@ public class TestYAMLConfiguration { handler.load(new File("src/test/resources/org/apache/commons/configuration2/yaml/cycle.yaml")); } - @Test - void testDoubleStringValues() { - final Object property = yamlConfiguration.getProperty("key5.example2"); - assertEquals(Arrays.asList("a", "a", "value"), property); - } - @Test void testDoubleStringEmptyValues() { final Object property = yamlConfiguration.getProperty("key5.example1"); assertEquals(Arrays.asList("", "", "value"), property); } + @Test + void testDoubleStringValues() { + final Object property = yamlConfiguration.getProperty("key5.example2"); + assertEquals(Arrays.asList("a", "a", "value"), property); + } + @Test void testGetPropertyDictionary() { assertEquals("Martin D'vloper", yamlConfiguration.getProperty("martin.name")); diff --git a/src/test/java/org/apache/commons/configuration2/io/TestProvidedURLLocationStrategy.java b/src/test/java/org/apache/commons/configuration2/io/TestProvidedURLLocationStrategy.java index 2002246da..cc3d87294 100644 --- a/src/test/java/org/apache/commons/configuration2/io/TestProvidedURLLocationStrategy.java +++ b/src/test/java/org/apache/commons/configuration2/io/TestProvidedURLLocationStrategy.java @@ -66,6 +66,20 @@ public class TestProvidedURLLocationStrategy { assertNull(ProvidedURLLocationStrategy.builder().get().locate(fs, locator)); } + @Test + void testLocateSchemes() { + final FileSystem fs = mock(FileSystem.class); + final URL url = ConfigurationAssert.getTestURL("test.xml"); + final FileLocator locator = FileLocatorUtils.fileLocator().sourceURL(url).create(); + final Set<String> schemes = new HashSet<>(); + final StrategyBuilder<ProvidedURLLocationStrategy> builder = ProvidedURLLocationStrategy.builder(); + assertEquals("file", builder.setSchemes(schemes).get().locate(fs, locator).getProtocol()); + schemes.add("foo"); + assertThrows(ConfigurationDeniedException.class, () -> builder.setSchemes(schemes).get().locate(fs, locator)); + schemes.add("file"); + assertSame(url, builder.setSchemes(schemes).get().locate(fs, locator)); + } + /** * Tests a successful locate() operation. */ @@ -87,18 +101,4 @@ public class TestProvidedURLLocationStrategy { final FileLocator locator = FileLocatorUtils.fileLocator().sourceURL(url).create(); assertSame(url, ProvidedURLLocationStrategy.builder().get().locate(fs, locator)); } - - @Test - void testLocateSchemes() { - final FileSystem fs = mock(FileSystem.class); - final URL url = ConfigurationAssert.getTestURL("test.xml"); - final FileLocator locator = FileLocatorUtils.fileLocator().sourceURL(url).create(); - final Set<String> schemes = new HashSet<>(); - final StrategyBuilder<ProvidedURLLocationStrategy> builder = ProvidedURLLocationStrategy.builder(); - assertEquals("file", builder.setSchemes(schemes).get().locate(fs, locator).getProtocol()); - schemes.add("foo"); - assertThrows(ConfigurationDeniedException.class, () -> builder.setSchemes(schemes).get().locate(fs, locator)); - schemes.add("file"); - assertSame(url, builder.setSchemes(schemes).get().locate(fs, locator)); - } }
