Search in sources :

Example 41 with ProcessorTest

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

the class BuiltInTest method shouldApplyBuiltInOnCalendarToZonedDateTime.

@ProcessorTest
@WithClasses(CalendarToZonedDateTimeMapper.class)
public void shouldApplyBuiltInOnCalendarToZonedDateTime() throws ParseException {
    assertThat(CalendarToZonedDateTimeMapper.INSTANCE.map(null)).isNull();
    CalendarProperty source = new CalendarProperty();
    source.setProp(createCalendar("02.03.1999"));
    source.publicProp = createCalendar("02.03.2016");
    ZonedDateTimeProperty target = CalendarToZonedDateTimeMapper.INSTANCE.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getProp()).isNotNull();
    assertThat(target.getProp()).isEqualTo(ZonedDateTime.of(1999, 3, 2, 0, 0, 0, 0, ZoneId.systemDefault()));
    assertThat(target.publicProp).isNotNull();
    assertThat(target.publicProp).isEqualTo(ZonedDateTime.of(2016, 3, 2, 0, 0, 0, 0, ZoneId.systemDefault()));
}
Also used : XmlGregorianCalendarProperty(org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty) CalendarProperty(org.mapstruct.ap.test.builtin.bean.CalendarProperty) ZonedDateTimeProperty(org.mapstruct.ap.test.builtin.java8time.bean.ZonedDateTimeProperty) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 42 with ProcessorTest

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

the class JodaTimeTest method shouldMapXmlGregorianCalendarToLocalDateTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToLocalDateTime.class)
public void shouldMapXmlGregorianCalendarToLocalDateTime() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(2010, 1, 15, 1, 1, 1, 100, 60);
    in.setxMLGregorianCalendar(xcal);
    LocalDateTimeBean res = XmlGregorianCalendarToLocalDateTime.INSTANCE.toDateTimeBean(in);
    assertThat(res.getLocalDateTime().getYear()).isEqualTo(2010);
    assertThat(res.getLocalDateTime().getMonthOfYear()).isEqualTo(1);
    assertThat(res.getLocalDateTime().getDayOfMonth()).isEqualTo(15);
    assertThat(res.getLocalDateTime().getHourOfDay()).isEqualTo(1);
    assertThat(res.getLocalDateTime().getMinuteOfHour()).isEqualTo(1);
    assertThat(res.getLocalDateTime().getSecondOfMinute()).isEqualTo(1);
    assertThat(res.getLocalDateTime().getMillisOfSecond()).isEqualTo(100);
}
Also used : LocalDateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 43 with ProcessorTest

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

the class JodaTimeTest method shouldMapXmlGregorianCalendarWithoutSecondsAndTimeZoneToDateTimeWithDefaultTimeZone.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldMapXmlGregorianCalendarWithoutSecondsAndTimeZoneToDateTimeWithDefaultTimeZone() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    xcal.setYear(1999);
    xcal.setMonth(5);
    xcal.setDay(25);
    xcal.setHour(23);
    xcal.setMinute(34);
    in.setxMLGregorianCalendar(xcal);
    DateTimeBean res = XmlGregorianCalendarToDateTime.INSTANCE.toDateTimeBean(in);
    assertThat(res.getDateTime().getYear()).isEqualTo(1999);
    assertThat(res.getDateTime().getMonthOfYear()).isEqualTo(5);
    assertThat(res.getDateTime().getDayOfMonth()).isEqualTo(25);
    assertThat(res.getDateTime().getHourOfDay()).isEqualTo(23);
    assertThat(res.getDateTime().getMinuteOfHour()).isEqualTo(34);
    assertThat(res.getDateTime().getSecondOfMinute()).isEqualTo(0);
    assertThat(res.getDateTime().getMillisOfSecond()).isEqualTo(0);
    assertThat(res.getDateTime().getZone().getOffset(0)).isEqualTo(DateTimeZone.getDefault().getOffset(0));
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalDateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean) DateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 44 with ProcessorTest

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

the class JodaTimeTest method shouldMapIncompleteDateTimeToXmlGregorianCalendar.

@ProcessorTest
@WithClasses(DateTimeToXmlGregorianCalendar.class)
public void shouldMapIncompleteDateTimeToXmlGregorianCalendar() {
    DateTimeBean in = new DateTimeBean();
    DateTime dt = new DateTime(2010, 1, 15, 1, 1);
    in.setDateTime(dt);
    XmlGregorianCalendarBean res = DateTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean(in);
    assertThat(res.getxMLGregorianCalendar().getYear()).isEqualTo(2010);
    assertThat(res.getxMLGregorianCalendar().getMonth()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getDay()).isEqualTo(15);
    assertThat(res.getxMLGregorianCalendar().getHour()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getMinute()).isEqualTo(1);
}
Also used : XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalDateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean) DateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean) XmlGregorianCalendarToDateTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToDateTime) XmlGregorianCalendarToLocalDateTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 45 with ProcessorTest

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

the class JodaTimeTest method shouldMapXmlGregorianCalendarWithoutMillisToLocalDateTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToLocalDateTime.class)
public void shouldMapXmlGregorianCalendarWithoutMillisToLocalDateTime() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    xcal.setYear(1999);
    xcal.setMonth(5);
    xcal.setDay(25);
    xcal.setHour(23);
    xcal.setMinute(34);
    xcal.setSecond(45);
    in.setxMLGregorianCalendar(xcal);
    LocalDateTimeBean res = XmlGregorianCalendarToLocalDateTime.INSTANCE.toDateTimeBean(in);
    assertThat(res.getLocalDateTime().getYear()).isEqualTo(1999);
    assertThat(res.getLocalDateTime().getMonthOfYear()).isEqualTo(5);
    assertThat(res.getLocalDateTime().getDayOfMonth()).isEqualTo(25);
    assertThat(res.getLocalDateTime().getHourOfDay()).isEqualTo(23);
    assertThat(res.getLocalDateTime().getMinuteOfHour()).isEqualTo(34);
    assertThat(res.getLocalDateTime().getSecondOfMinute()).isEqualTo(45);
    assertThat(res.getLocalDateTime().getMillisOfSecond()).isEqualTo(0);
}
Also used : LocalDateTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

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