Search in sources :

Example 36 with FormattingConversionService

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

the class WebFluxAutoConfigurationTests method customDateFormat.

@Test
void customDateFormat() {
    this.contextRunner.withPropertyValues("spring.webflux.format.date: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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with FormattingConversionService

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

the class WebFluxAutoConfigurationTests method defaultDateTimeFormat.

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

Example 38 with FormattingConversionService

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

the class ConversionServiceArguments method with.

static Stream<? extends Arguments> with(Consumer<FormattingConversionService> initializer) {
    FormattingConversionService withoutDefaults = new FormattingConversionService();
    initializer.accept(withoutDefaults);
    return Stream.of(Arguments.of(new NamedConversionService(withoutDefaults, "Without defaults conversion service")), Arguments.of(new NamedConversionService(new ApplicationConversionService(), "Application conversion service")));
}
Also used : FormattingConversionService(org.springframework.format.support.FormattingConversionService)

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