Search in sources :

Example 1 with LocalTimeBean

use of org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapXmlGregorianCalendarToLocalTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToLocalTime.class)
public void shouldMapXmlGregorianCalendarToLocalTime() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendarTime(1, 1, 1, 100, 60);
    in.setxMLGregorianCalendar(xcal);
    LocalTimeBean res = XmlGregorianCalendarToLocalTime.INSTANCE.toLocalTimeBean(in);
    assertThat(res.getLocalTime().getHourOfDay()).isEqualTo(1);
    assertThat(res.getLocalTime().getMinuteOfHour()).isEqualTo(1);
    assertThat(res.getLocalTime().getSecondOfMinute()).isEqualTo(1);
    assertThat(res.getLocalTime().getMillisOfSecond()).isEqualTo(100);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 2 with LocalTimeBean

use of org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapXmlGregorianCalendarWithoutMillisToLocalTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToLocalTime.class)
public void shouldMapXmlGregorianCalendarWithoutMillisToLocalTime() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    xcal.setHour(23);
    xcal.setMinute(34);
    xcal.setSecond(45);
    in.setxMLGregorianCalendar(xcal);
    LocalTimeBean res = XmlGregorianCalendarToLocalTime.INSTANCE.toLocalTimeBean(in);
    assertThat(res.getLocalTime().getHourOfDay()).isEqualTo(23);
    assertThat(res.getLocalTime().getMinuteOfHour()).isEqualTo(34);
    assertThat(res.getLocalTime().getSecondOfMinute()).isEqualTo(45);
    assertThat(res.getLocalTime().getMillisOfSecond()).isEqualTo(0);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 3 with LocalTimeBean

use of org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapXmlGregorianCalendarWithoutSecondsToLocalTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToLocalTime.class)
public void shouldMapXmlGregorianCalendarWithoutSecondsToLocalTime() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    xcal.setHour(23);
    xcal.setMinute(34);
    xcal.setTimezone(60);
    in.setxMLGregorianCalendar(xcal);
    LocalTimeBean res = XmlGregorianCalendarToLocalTime.INSTANCE.toLocalTimeBean(in);
    assertThat(res.getLocalTime().getHourOfDay()).isEqualTo(23);
    assertThat(res.getLocalTime().getMinuteOfHour()).isEqualTo(34);
    assertThat(res.getLocalTime().getSecondOfMinute()).isEqualTo(0);
    assertThat(res.getLocalTime().getMillisOfSecond()).isEqualTo(0);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 4 with LocalTimeBean

use of org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean in project mapstruct by mapstruct.

the class JodaTimeTest method shouldNotMapXmlGregorianCalendarWithoutMinutesToLocalTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToLocalTime.class)
public void shouldNotMapXmlGregorianCalendarWithoutMinutesToLocalTime() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    xcal.setYear(1999);
    xcal.setMonth(5);
    xcal.setDay(25);
    xcal.setHour(23);
    in.setxMLGregorianCalendar(xcal);
    LocalTimeBean res = XmlGregorianCalendarToLocalTime.INSTANCE.toLocalTimeBean(in);
    assertThat(res.getLocalTime()).isNull();
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 5 with LocalTimeBean

use of org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean in project mapstruct by mapstruct.

the class JodaTimeTest method shouldMapIncompleteLocalTimeToXmlGregorianCalendar.

@ProcessorTest
@WithClasses(LocalTimeToXmlGregorianCalendar.class)
public void shouldMapIncompleteLocalTimeToXmlGregorianCalendar() {
    LocalTimeBean in = new LocalTimeBean();
    LocalTime dt = new LocalTime(1, 1, 0, 100);
    in.setLocalTime(dt);
    XmlGregorianCalendarBean res = LocalTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean(in);
    assertThat(res.getxMLGregorianCalendar().getYear()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getMonth()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getDay()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getHour()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getMinute()).isEqualTo(1);
    assertThat(res.getxMLGregorianCalendar().getSecond()).isEqualTo(0);
    assertThat(res.getxMLGregorianCalendar().getMillisecond()).isEqualTo(100);
    assertThat(res.getxMLGregorianCalendar().getTimezone()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
}
Also used : LocalTime(org.joda.time.LocalTime) XmlGregorianCalendarToLocalTime(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalTime) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalTimeBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

LocalTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalTimeBean)5 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)5 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)5 WithClasses (org.mapstruct.ap.testutil.WithClasses)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)4 LocalTime (org.joda.time.LocalTime)1 XmlGregorianCalendarToLocalTime (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalTime)1