Commit a4a19e1e authored by Stephane Nicoll's avatar Stephane Nicoll

Polish

This commit makes sure that the defaultValue has to be provided in
assertions. If not present, no defaultValue should be generated.
parent 674170a3
......@@ -122,6 +122,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
.withDescription("The name of this simple properties.")
.withDefaultValue("boot").withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class)
.withDefaultValue(false)
.fromSource(SimpleProperties.class).withDescription("A simple flag.")
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
......@@ -148,7 +149,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-byte", Byte.class));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-primitive-byte", Byte.class));
.has(Metadata.withProperty("simple.type.my-primitive-byte", Byte.class)
.withDefaultValue(0));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-char", Character.class));
assertThat(metadata).has(
......@@ -156,19 +158,23 @@ public class ConfigurationMetadataAnnotationProcessorTests {
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-boolean", Boolean.class));
assertThat(metadata).has(
Metadata.withProperty("simple.type.my-primitive-boolean", Boolean.class));
Metadata.withProperty("simple.type.my-primitive-boolean", Boolean.class)
.withDefaultValue(false));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-short", Short.class));
assertThat(metadata).has(
Metadata.withProperty("simple.type.my-primitive-short", Short.class));
Metadata.withProperty("simple.type.my-primitive-short", Short.class)
.withDefaultValue(0));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-integer", Integer.class));
assertThat(metadata).has(
Metadata.withProperty("simple.type.my-primitive-integer", Integer.class));
Metadata.withProperty("simple.type.my-primitive-integer", Integer.class)
.withDefaultValue(0));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-long", Long.class));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-primitive-long", Long.class));
.has(Metadata.withProperty("simple.type.my-primitive-long", Long.class)
.withDefaultValue(0));
assertThat(metadata)
.has(Metadata.withProperty("simple.type.my-double", Double.class));
assertThat(metadata).has(
......@@ -230,7 +236,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
.withNoDeprecation().fromSource(type));
assertThat(metadata)
.has(Metadata.withProperty("not.deprecated.flag", Boolean.class)
.withNoDeprecation().fromSource(type));
.withDefaultValue(false).withNoDeprecation().fromSource(type));
}
@Test
......@@ -239,7 +245,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
ConfigurationMetadata metadata = compile(type);
assertThat(metadata).has(Metadata.withGroup("boxing").fromSource(type));
assertThat(metadata).has(
Metadata.withProperty("boxing.flag", Boolean.class).fromSource(type));
Metadata.withProperty("boxing.flag", Boolean.class)
.withDefaultValue(false).fromSource(type));
assertThat(metadata).has(
Metadata.withProperty("boxing.counter", Integer.class).fromSource(type));
}
......@@ -271,7 +278,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
.fromSource(SimpleMethodConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
.fromSource(SimpleMethodConfig.Foo.class));
.withDefaultValue(false).fromSource(SimpleMethodConfig.Foo.class));
}
@Test
......@@ -288,7 +295,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
assertThat(metadata).has(Metadata.withProperty("conflict.name", String.class)
.fromSource(MethodAndClassConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("conflict.flag", Boolean.class)
.fromSource(MethodAndClassConfig.Foo.class));
.withDefaultValue(false).fromSource(MethodAndClassConfig.Foo.class));
assertThat(metadata).has(Metadata.withProperty("conflict.value", String.class)
.fromSource(MethodAndClassConfig.class));
}
......@@ -308,6 +315,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
.fromSource(DeprecatedMethodConfig.Foo.class)
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
.withDefaultValue(false)
.fromSource(DeprecatedMethodConfig.Foo.class)
.withDeprecation(null, null));
}
......@@ -323,6 +331,7 @@ public class ConfigurationMetadataAnnotationProcessorTests {
org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
.withDeprecation(null, null));
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class)
.withDefaultValue(false)
.fromSource(
org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
.withDeprecation(null, null));
......@@ -857,25 +866,33 @@ public class ConfigurationMetadataAnnotationProcessorTests {
ConfigurationMetadata metadata = project.fullBuild();
assertThat(project.getOutputFile(MetadataStore.METADATA_PATH).exists()).isTrue();
assertThat(metadata).has(
Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
Metadata.withProperty("foo.counter").fromSource(FooProperties.class)
.withDefaultValue(0));
assertThat(metadata).has(
Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
Metadata.withProperty("bar.counter").fromSource(BarProperties.class)
.withDefaultValue(0));
metadata = project.incrementalBuild(BarProperties.class);
assertThat(metadata).has(
Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
Metadata.withProperty("foo.counter").fromSource(FooProperties.class)
.withDefaultValue(0));
assertThat(metadata).has(
Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
Metadata.withProperty("bar.counter").fromSource(BarProperties.class)
.withDefaultValue(0));
project.addSourceCode(BarProperties.class,
BarProperties.class.getResourceAsStream("BarProperties.snippet"));
metadata = project.incrementalBuild(BarProperties.class);
assertThat(metadata).has(Metadata.withProperty("bar.extra"));
assertThat(metadata).has(Metadata.withProperty("foo.counter"));
assertThat(metadata).has(Metadata.withProperty("bar.counter"));
assertThat(metadata).has(Metadata.withProperty("foo.counter")
.withDefaultValue(0));
assertThat(metadata).has(Metadata.withProperty("bar.counter")
.withDefaultValue(0));
project.revert(BarProperties.class);
metadata = project.incrementalBuild(BarProperties.class);
assertThat(metadata).isNotEqualTo(Metadata.withProperty("bar.extra"));
assertThat(metadata).has(Metadata.withProperty("foo.counter"));
assertThat(metadata).has(Metadata.withProperty("bar.counter"));
assertThat(metadata).has(Metadata.withProperty("foo.counter")
.withDefaultValue(0));
assertThat(metadata).has(Metadata.withProperty("bar.counter")
.withDefaultValue(0));
}
@Test
......@@ -883,12 +900,15 @@ public class ConfigurationMetadataAnnotationProcessorTests {
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class,
BarProperties.class);
ConfigurationMetadata metadata = project.fullBuild();
assertThat(metadata).has(Metadata.withProperty("foo.counter"));
assertThat(metadata).has(Metadata.withProperty("bar.counter"));
assertThat(metadata).has(Metadata.withProperty("foo.counter")
.withDefaultValue(0));
assertThat(metadata).has(Metadata.withProperty("bar.counter")
.withDefaultValue(0));
project.replaceText(BarProperties.class, "@ConfigurationProperties",
"//@ConfigurationProperties");
metadata = project.incrementalBuild(BarProperties.class);
assertThat(metadata).has(Metadata.withProperty("foo.counter"));
assertThat(metadata).has(Metadata.withProperty("foo.counter")
.withDefaultValue(0));
assertThat(metadata).isNotEqualTo(Metadata.withProperty("bar.counter"));
}
......@@ -898,20 +918,24 @@ public class ConfigurationMetadataAnnotationProcessorTests {
BarProperties.class);
ConfigurationMetadata metadata = project.fullBuild();
assertThat(metadata).has(
Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
Metadata.withProperty("foo.counter").fromSource(FooProperties.class)
.withDefaultValue(0));
assertThat(metadata).has(
Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
Metadata.withProperty("bar.counter").fromSource(BarProperties.class)
.withDefaultValue(0));
assertThat(metadata).doesNotHave(Metadata.withProperty("bar.counter")
.fromSource(RenamedBarProperties.class));
project.delete(BarProperties.class);
project.add(RenamedBarProperties.class);
metadata = project.incrementalBuild(RenamedBarProperties.class);
assertThat(metadata).has(
Metadata.withProperty("foo.counter").fromSource(FooProperties.class));
Metadata.withProperty("foo.counter").fromSource(FooProperties.class)
.withDefaultValue(0));
assertThat(metadata).doesNotHave(
Metadata.withProperty("bar.counter").fromSource(BarProperties.class));
Metadata.withProperty("bar.counter").fromSource(BarProperties.class)
.withDefaultValue(0));
assertThat(metadata).has(Metadata.withProperty("bar.counter")
.fromSource(RenamedBarProperties.class));
.withDefaultValue(0).fromSource(RenamedBarProperties.class));
}
private void assertSimpleLombokProperties(ConfigurationMetadata metadata,
......
......@@ -151,6 +151,9 @@ public final class Metadata {
.nullSafeEquals(this.defaultValue, itemMetadata.getDefaultValue())) {
return false;
}
if (this.defaultValue == null && itemMetadata.getDefaultValue() != null) {
return false;
}
if (this.description != null
&& !this.description.equals(itemMetadata.getDescription())) {
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment