Search in sources :

Example 1 with DateTimeFormat

use of org.springframework.format.annotation.DateTimeFormat in project spring-boot by spring-projects.

the class BinderTests method bindWhenHasAnnotationsShouldChangeConvertedValue.

@Test
void bindWhenHasAnnotationsShouldChangeConvertedValue() {
    this.sources.add(new MockConfigurationPropertySource("foo", "2014-04-01T01:30:00.000-05:00"));
    DateTimeFormat annotation = AnnotationUtils.synthesizeAnnotation(Collections.singletonMap("iso", DateTimeFormat.ISO.DATE_TIME), DateTimeFormat.class, null);
    LocalDate result = this.binder.bind("foo", Bindable.of(LocalDate.class).withAnnotations(annotation)).get();
    assertThat(result.toString()).isEqualTo("2014-04-01");
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) LocalDate(java.time.LocalDate) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) Test(org.junit.jupiter.api.Test)

Aggregations

LocalDate (java.time.LocalDate)1 Test (org.junit.jupiter.api.Test)1 MockConfigurationPropertySource (org.springframework.boot.context.properties.source.MockConfigurationPropertySource)1 DateTimeFormat (org.springframework.format.annotation.DateTimeFormat)1