Search in sources :

Example 1 with EnabledOnJre

use of org.junit.jupiter.api.condition.EnabledOnJre in project mapstruct by mapstruct.

the class JodaConversionTest method testSourceToTargetMappingForStrings.

@ProcessorTest
@EnabledOnJre(JRE.JAVA_8)
public // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+
void testSourceToTargetMappingForStrings() {
    Source src = new Source();
    src.setLocalTime(new LocalTime(0, 0));
    src.setLocalDate(new LocalDate(2014, 1, 1));
    src.setLocalDateTime(new LocalDateTime(2014, 1, 1, 0, 0));
    src.setDateTime(new DateTime(2014, 1, 1, 0, 0, 0, DateTimeZone.UTC));
    // with given format
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(src);
    assertThat(target).isNotNull();
    assertThat(target.getDateTime()).isEqualTo("01.01.2014 00:00 UTC");
    assertThat(target.getLocalDateTime()).isEqualTo("01.01.2014 00:00");
    assertThat(target.getLocalDate()).isEqualTo("01.01.2014");
    assertThat(target.getLocalTime()).isEqualTo("00:00");
    // and now with default mappings
    target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping(src);
    assertThat(target).isNotNull();
    assertThat(target.getDateTime()).isEqualTo("1. Januar 2014 00:00:00 UTC");
    assertThat(target.getLocalDateTime()).isEqualTo("1. Januar 2014 00:00:00");
    assertThat(target.getLocalDate()).isEqualTo("1. Januar 2014");
    assertThat(target.getLocalTime()).isEqualTo("00:00:00");
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) LocalTime(org.joda.time.LocalTime) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) EnabledOnJre(org.junit.jupiter.api.condition.EnabledOnJre)

Aggregations

DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 LocalDateTime (org.joda.time.LocalDateTime)1 LocalTime (org.joda.time.LocalTime)1 EnabledOnJre (org.junit.jupiter.api.condition.EnabledOnJre)1 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)1