Search in sources :

Example 11 with FormattingConversionService

use of org.springframework.format.support.FormattingConversionService in project spring-boot by spring-projects.

the class WebFluxAutoConfigurationTests method customTimeFormat.

@Test
void customTimeFormat() {
    this.contextRunner.withPropertyValues("spring.webflux.format.time=HH:mm:ss").run((context) -> {
        FormattingConversionService conversionService = context.getBean(FormattingConversionService.class);
        LocalTime time = LocalTime.of(11, 43, 10);
        assertThat(conversionService.convert(time, String.class)).isEqualTo("11:43:10");
    });
}
Also used : LocalTime(java.time.LocalTime) FormattingConversionService(org.springframework.format.support.FormattingConversionService) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with FormattingConversionService

use of org.springframework.format.support.FormattingConversionService in project spring-boot by spring-projects.

the class WebFluxAutoConfigurationTests method defaultTimeFormat.

@Test
void defaultTimeFormat() {
    this.contextRunner.run((context) -> {
        FormattingConversionService conversionService = context.getBean(FormattingConversionService.class);
        LocalTime time = LocalTime.of(11, 43, 10);
        assertThat(conversionService.convert(time, String.class)).isEqualTo(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(time));
    });
}
Also used : LocalTime(java.time.LocalTime) FormattingConversionService(org.springframework.format.support.FormattingConversionService) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with FormattingConversionService

use of org.springframework.format.support.FormattingConversionService in project spring-boot by spring-projects.

the class WebMvcAutoConfigurationTests method defaultTimeFormat.

@Test
void defaultTimeFormat() {
    this.contextRunner.run((context) -> {
        FormattingConversionService conversionService = context.getBean(FormattingConversionService.class);
        LocalTime time = LocalTime.of(11, 43, 10);
        assertThat(conversionService.convert(time, String.class)).isEqualTo(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(time));
    });
}
Also used : LocalTime(java.time.LocalTime) FormattingConversionService(org.springframework.format.support.FormattingConversionService) Test(org.junit.jupiter.api.Test)

Example 14 with FormattingConversionService

use of org.springframework.format.support.FormattingConversionService in project spring-boot by spring-projects.

the class WebMvcAutoConfigurationTests method customTimeFormat.

@Test
void customTimeFormat() {
    this.contextRunner.withPropertyValues("spring.mvc.format.time=HH:mm:ss").run((context) -> {
        FormattingConversionService conversionService = context.getBean(FormattingConversionService.class);
        LocalTime time = LocalTime.of(11, 43, 10);
        assertThat(conversionService.convert(time, String.class)).isEqualTo("11:43:10");
    });
}
Also used : LocalTime(java.time.LocalTime) FormattingConversionService(org.springframework.format.support.FormattingConversionService) Test(org.junit.jupiter.api.Test)

Example 15 with FormattingConversionService

use of org.springframework.format.support.FormattingConversionService in project spring-boot by spring-projects.

the class WebMvcAutoConfigurationTests method customDateFormatWithDeprecatedProperty.

@Test
void customDateFormatWithDeprecatedProperty() {
    this.contextRunner.withPropertyValues("spring.mvc.date-format:dd*MM*yyyy").run((context) -> {
        FormattingConversionService conversionService = context.getBean(FormattingConversionService.class);
        Date date = Date.from(ZonedDateTime.of(1988, 6, 25, 20, 30, 0, 0, ZoneId.systemDefault()).toInstant());
        assertThat(conversionService.convert(date, String.class)).isEqualTo("25*06*1988");
    });
}
Also used : FormattingConversionService(org.springframework.format.support.FormattingConversionService) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

FormattingConversionService (org.springframework.format.support.FormattingConversionService)38 Test (org.junit.jupiter.api.Test)27 DefaultFormattingConversionService (org.springframework.format.support.DefaultFormattingConversionService)13 Date (java.util.Date)8 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)8 Locale (java.util.Locale)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 DerivedTestBean (org.springframework.beans.testfixture.beans.DerivedTestBean)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)6 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)6 TestBean (org.springframework.beans.testfixture.beans.TestBean)6 NumberStyleFormatter (org.springframework.format.number.NumberStyleFormatter)6 ParseException (java.text.ParseException)5 LocalDateTime (java.time.LocalDateTime)4 LocalTime (java.time.LocalTime)4 List (java.util.List)4 Bean (org.springframework.context.annotation.Bean)4 StringReader (java.io.StringReader)3 Document (org.dom4j.Document)3 Element (org.dom4j.Element)3