Skip to content

Commit

Permalink
Use modern API
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jul 12, 2023
1 parent 3ed973d commit 8f5cbe7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package org.apache.commons.configuration2.spring;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.configuration2.Configuration;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.core.env.EnumerablePropertySource;

/**
Expand All @@ -40,11 +40,8 @@ protected ConfigurationPropertySource(final String name) {
@Override
public String[] getPropertyNames() {
final List<String> keys = new ArrayList<>();
final Iterator<String> keysIterator = source.getKeys();
while (keysIterator.hasNext()) {
keys.add(keysIterator.next());
}
return keys.toArray(new String[keys.size()]);
source.getKeys().forEachRemaining(keys::add);
return keys.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;

/**
* test for ConfigurationPropertySource
* Tests {@link ConfigurationPropertySource}.
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration
Expand All @@ -44,7 +44,8 @@ public class TestConfigurationPropertySource {
static class Config {

@Bean
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(final ConfigurableEnvironment env) {
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(
final ConfigurableEnvironment env) {
final PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
// https://jira.spring.io/browse/SPR-9631 may simplify this in
// future
Expand All @@ -55,13 +56,13 @@ public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer
return configurer;
}
}

private static final String TEST_PROPERTY = "test.property";

private static final String TEST_SYSTEM_PROPERTY = "test.system.property";

private static final String TEST_VALUE = "testVALUE";


private static ConfigurationPropertySource createConfigPropertySource() {
final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
propertiesConfiguration.addProperty(TEST_PROPERTY, TEST_VALUE);
Expand Down Expand Up @@ -91,6 +92,8 @@ public void testValueInjection() {
}

@Test
public void testSystemPropertyValueInjection() { assertEquals(TEST_VALUE, systemPropertyValue); }
public void testSystemPropertyValueInjection() {
assertEquals(TEST_VALUE, systemPropertyValue);
}

}

0 comments on commit 8f5cbe7

Please sign in to comment.