Search in sources :

Example 1 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class SpringDecoratorTest method shouldDelegateNonDecoratedMethodsToDefaultImplementation.

@ProcessorTest
public void shouldDelegateNonDecoratedMethodsToDefaultImplementation() {
    // given
    Address address = new Address("42 Ocean View Drive");
    // when
    AddressDto addressDto = personMapper.addressToAddressDto(address);
    // then
    assertThat(addressDto).isNotNull();
    assertThat(addressDto.getAddressLine()).isEqualTo("42 Ocean View Drive");
}
Also used : Address(org.mapstruct.ap.test.decorator.Address) AddressDto(org.mapstruct.ap.test.decorator.AddressDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 2 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class JodaConversionTest method testSourceToTargetMappingForStringsJdk11.

@ProcessorTest
@EnabledForJreRange(min = JRE.JAVA_11)
public // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+
void testSourceToTargetMappingForStringsJdk11() {
    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 um 00:00:00 UTC");
    assertThat(target.getLocalDateTime()).isEqualTo("1. Januar 2014 um 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) EnabledForJreRange(org.junit.jupiter.api.condition.EnabledForJreRange) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 3 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class JodaConversionTest method testCalendar.

@ProcessorTest
public void testCalendar() {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("CET"));
    DateTime dateTimeWithCalendar = new DateTime(calendar);
    Source src = new Source();
    src.setDateTimeForCalendarConversion(dateTimeWithCalendar);
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(src);
    assertThat(target).isNotNull();
    assertThat(target.getDateTimeForCalendarConversion().getTime()).isEqualTo(calendar.getTime());
    Source mappedSource = SourceTargetMapper.INSTANCE.targetToSource(target);
    assertThat(mappedSource).isNotNull();
    assertThat(mappedSource.getDateTimeForCalendarConversion()).isEqualTo(dateTimeWithCalendar);
}
Also used : Calendar(java.util.Calendar) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 4 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class JodaConversionTest method testLocalDateTimeToString.

@ProcessorTest
public void testLocalDateTimeToString() {
    Source src = new Source();
    src.setLocalDateTime(new LocalDateTime(2014, 1, 1, 0, 0));
    Target target = SourceTargetMapper.INSTANCE.sourceToTargetLocalDateTimeMapped(src);
    assertThat(target).isNotNull();
    assertThat(target.getLocalDateTime()).isEqualTo("01.01.2014 00:00");
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 5 with ProcessorTest

use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.

the class JodaConversionTest method testStringToLocalDateTime.

@ProcessorTest
public void testStringToLocalDateTime() {
    String dateTimeAsString = "01.01.2014 00:00";
    Target target = new Target();
    target.setLocalDateTime(dateTimeAsString);
    LocalDateTime sourceDateTime = new LocalDateTime(2014, 1, 1, 0, 0, 0);
    Source src = SourceTargetMapper.INSTANCE.targetToSourceLocalDateTimeMapped(target);
    assertThat(src).isNotNull();
    assertThat(src.getLocalDateTime()).isEqualTo(sourceDateTime);
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)314 WithClasses (org.mapstruct.ap.testutil.WithClasses)118 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)51 IssueKey (org.mapstruct.ap.testutil.IssueKey)39 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)22 Date (java.util.Date)16 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 Calendar (java.util.Calendar)13 LocalDateTime (org.joda.time.LocalDateTime)13 CarDto (org.mapstruct.ap.test.complex._target.CarDto)13 Car (org.mapstruct.ap.test.complex.source.Car)13 PersonDto (org.mapstruct.ap.test.constructor.PersonDto)13 GregorianCalendar (java.util.GregorianCalendar)12 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)12 BigDecimal (java.math.BigDecimal)11 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)11 DriverAndCarDto (org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto)11 DateTime (org.joda.time.DateTime)10