Verify that Java Time config properties can be bound

Closes gh-9237
pull/9851/head
Andy Wilkinson 7 years ago
parent 6518ffe801
commit b52ece1ac7

@ -16,6 +16,7 @@
package org.springframework.boot.context.properties;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
@ -458,6 +459,19 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
assertThat(second.getTwo()).isEqualTo("baz");
}
@Test
public void javaTimeDurationCanBeBound() throws Exception {
this.context = new AnnotationConfigApplicationContext();
MutablePropertySources sources = this.context.getEnvironment()
.getPropertySources();
sources.addFirst(new MapPropertySource("test",
Collections.singletonMap("test.duration", "PT1M")));
this.context.register(DurationProperty.class);
this.context.refresh();
Duration duration = this.context.getBean(DurationProperty.class).getDuration();
assertThat(duration.getSeconds()).isEqualTo(60);
}
private void assertBindingFailure(int errorCount) {
try {
this.context.refresh();
@ -970,6 +984,23 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
}
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "test")
public static class DurationProperty {
private Duration duration;
public Duration getDuration() {
return this.duration;
}
public void setDuration(Duration duration) {
this.duration = duration;
}
}
@Configuration
@EnableConfigurationProperties(PropertyWithoutConfigurationPropertiesAnnotation.class)
public static class ConfigurationPropertiesWithoutAnnotation {

Loading…
Cancel
Save