Browse Source

Fix equality check for multiple values

This commit fixes the changelog generator to not flag two identical
arrays as changed. Previously, any candidate property with an array
of default values were flagged incorrectly.

Closes gh-49272
pull/49282/head
Stéphane Nicoll 4 weeks ago
parent
commit
c33e7585ac
  1. 2
      configuration-metadata/spring-boot-configuration-metadata-changelog-generator/src/main/java/org/springframework/boot/configurationmetadata/changelog/Difference.java
  2. 98
      configuration-metadata/spring-boot-configuration-metadata-changelog-generator/src/test/java/org/springframework/boot/configurationmetadata/changelog/DifferenceTests.java

2
configuration-metadata/spring-boot-configuration-metadata-changelog-generator/src/main/java/org/springframework/boot/configurationmetadata/changelog/Difference.java

@ -51,7 +51,7 @@ record Difference(DifferenceType type, ConfigurationMetadataProperty oldProperty @@ -51,7 +51,7 @@ record Difference(DifferenceType type, ConfigurationMetadataProperty oldProperty
&& newProperty.isDeprecated() && newProperty.getDeprecation().getLevel() == Level.ERROR) {
return new Difference(DifferenceType.DELETED, oldProperty, newProperty);
}
if (!Objects.equals(oldProperty.getDefaultValue(), newProperty.getDefaultValue())) {
if (!Objects.deepEquals(oldProperty.getDefaultValue(), newProperty.getDefaultValue())) {
return new Difference(DifferenceType.DEFAULT_CHANGED, oldProperty, newProperty);
}
return null;

98
configuration-metadata/spring-boot-configuration-metadata-changelog-generator/src/test/java/org/springframework/boot/configurationmetadata/changelog/DifferenceTests.java

@ -0,0 +1,98 @@ @@ -0,0 +1,98 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.configurationmetadata.changelog;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link Difference}.
*
* @author Stephane Nicoll
*/
class DifferenceTests {
@Nested
class DefaultChangedTests {
@Test
void sameValueComputesNoDifference() {
Difference difference = Difference.compute(createProperty("test.id", "test"),
createProperty("test.id", "test"));
assertThat(difference).isNull();
}
@Test
void bothNullComputesNoDifference() {
Difference difference = Difference.compute(createProperty("test.id", null),
createProperty("test.id", null));
assertThat(difference).isNull();
}
@Test
void nullThenNotNullDefaultChanged() {
Difference difference = Difference.compute(createProperty("test.id", null),
createProperty("test.id", "test"));
assertThat(difference).isNotNull();
assertThat(difference.type()).isEqualTo(DifferenceType.DEFAULT_CHANGED);
}
@Test
void notNullThenNullDefaultChanged() {
Difference difference = Difference.compute(createProperty("test.id", "test"),
createProperty("test.id", null));
assertThat(difference).isNotNull();
assertThat(difference.type()).isEqualTo(DifferenceType.DEFAULT_CHANGED);
}
@Test
void arrayEqualsComputesNoDifference() {
Difference difference = Difference.compute(createProperty("test.id", new Object[] { "one", "two" }),
createProperty("test.id", new Object[] { "one", "two" }));
assertThat(difference).isNull();
}
@Test
void arrayOrderChangedComputesDefaultChanged() {
Difference difference = Difference.compute(createProperty("test.id", new Object[] { "one", "two" }),
createProperty("test.id", new Object[] { "two", "one" }));
assertThat(difference).isNotNull();
assertThat(difference.type()).isEqualTo(DifferenceType.DEFAULT_CHANGED);
}
@Test
void arrayAdditionalValueComputesDefaultChanged() {
Difference difference = Difference.compute(createProperty("test.id", new Object[] { "one", "two" }),
createProperty("test.id", new Object[] { "one", "two", "three" }));
assertThat(difference).isNotNull();
assertThat(difference.type()).isEqualTo(DifferenceType.DEFAULT_CHANGED);
}
}
private static ConfigurationMetadataProperty createProperty(String id, Object defaultValue) {
ConfigurationMetadataProperty property = new ConfigurationMetadataProperty();
property.setId(id);
property.setDefaultValue(defaultValue);
return property;
}
}
Loading…
Cancel
Save