Skip to content

Commit

Permalink
filter and default fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bischoffdev committed Mar 14, 2022
1 parent 667f271 commit 1565caf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ and this project adheres to

Back to [Readme](README.md).

[1.2.1]: https://github.com/bischoffdev/property-aggregator/compare/v1.2.0...v1.2.1
[1.2.0]: https://github.com/bischoffdev/property-aggregator/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/bischoffdev/property-aggregator/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/bischoffdev/property-aggregator/tree/v1.0.0

## [1.2.1] - 2022-03-14

### Fixed
* Setting default without a filter removed all properties with default values

### Changed
* Default values are set regardless of filters.

## [1.2.0] - 2022-03-14

### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ of the property sources (in this example a properties file) does not include
value. If, however, "property1" __is__ specified in a property source, the
default value is replaced by the actual value.

__Note:__ If you use defaults and filters together, make sure that
properties with defaults also exist in the list of filter keys!
__Note:__ If you use defaults and filters together, properties with default
values are added to the final set regardless of filters!

## Logging the final properties

Expand Down
2 changes: 1 addition & 1 deletion library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>blog.softwaretester</groupId>
<artifactId>property-aggregator</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<packaging>jar</packaging>

<url>https://github.com/bischoffdev/property-aggregator</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ private PropertyAggregator(final Builder builder) {
// Process default values
for (Map.Entry<String, String> entry
: builder.propertyDefaultValues.entrySet()) {
if (!tmpProperties.contains(entry.getKey())
&& builder.filteredKeys.contains(entry.getKey())) {
if (!tmpProperties.stringPropertyNames().contains(entry.getKey())) {
tmpProperties.put(entry.getKey(), entry.getValue());
}
}
Expand Down Expand Up @@ -100,6 +99,7 @@ public Properties getPropertiesWithCustomPredicate(
));
Properties filteredProperties = new Properties();
filteredProperties.putAll(propertyMap);

return filteredProperties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public void validPropertiesWithDefaultValuesAndFilter() {
.withFilteredKeys(List.of("property2", "b"))
.build();
propertyAggregator.logFinalProperties();
Assertions.assertEquals(2, propertyAggregator.getPropertiesCount());
Assertions.assertNull(propertyAggregator.getProperty("a"));
Assertions.assertEquals(3, propertyAggregator.getPropertiesCount());
Assertions.assertEquals("1", propertyAggregator.getProperty("a"));
Assertions.assertEquals("2", propertyAggregator.getProperty("b"));
Assertions.assertNull(propertyAggregator.getProperty("property1"));
Assertions.assertEquals("value2_from_test1",
Expand Down

0 comments on commit 1565caf

Please sign in to comment.