|
27 | 27 | import org.joda.time.DateTimeZone; |
28 | 28 | import org.joda.time.LocalDate; |
29 | 29 | import org.joda.time.LocalDateTime; |
| 30 | +import org.joda.time.LocalTime; |
30 | 31 | import org.junit.Test; |
31 | 32 | import org.junit.runner.RunWith; |
32 | 33 | import org.mapstruct.ap.test.builtin.bean.jodatime.bean.DateTimeBean; |
33 | 34 | import org.mapstruct.ap.test.builtin.bean.jodatime.bean.LocalDateBean; |
34 | 35 | import org.mapstruct.ap.test.builtin.bean.jodatime.bean.LocalDateTimeBean; |
| 36 | +import org.mapstruct.ap.test.builtin.bean.jodatime.bean.LocalTimeBean; |
35 | 37 | import org.mapstruct.ap.test.builtin.bean.jodatime.bean.XmlGregorianCalendarBean; |
36 | 38 | import org.mapstruct.ap.test.builtin.bean.jodatime.mapper.DateTimeToXmlGregorianCalendar; |
37 | 39 | import org.mapstruct.ap.test.builtin.bean.jodatime.mapper.LocalDateTimeToXmlGregorianCalendar; |
38 | 40 | import org.mapstruct.ap.test.builtin.bean.jodatime.mapper.LocalDateToXmlGregorianCalendar; |
| 41 | +import org.mapstruct.ap.test.builtin.bean.jodatime.mapper.LocalTimeToXmlGregorianCalendar; |
39 | 42 | import org.mapstruct.ap.test.builtin.bean.jodatime.mapper.XmlGregorianCalendarToDateTime; |
40 | 43 | import org.mapstruct.ap.test.builtin.bean.jodatime.mapper.XmlGregorianCalendarToLocalDate; |
41 | 44 | import org.mapstruct.ap.test.builtin.bean.jodatime.mapper.XmlGregorianCalendarToLocalDateTime; |
| 45 | +import org.mapstruct.ap.test.builtin.bean.jodatime.mapper.XmlGregorianCalendarToLocalTime; |
42 | 46 | import org.mapstruct.ap.testutil.IssueKey; |
43 | 47 | import org.mapstruct.ap.testutil.WithClasses; |
44 | 48 | import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; |
|
49 | 53 | */ |
50 | 54 | @WithClasses({ |
51 | 55 | DateTimeBean.class, |
| 56 | + LocalTimeBean.class, |
52 | 57 | LocalDateBean.class, |
53 | 58 | LocalDateTimeBean.class, |
54 | 59 | XmlGregorianCalendarBean.class |
@@ -447,4 +452,99 @@ public void shouldNotMapXmlGregorianCalendarWithoutDaysToLocalDate() throws Exce |
447 | 452 | assertThat( res.getLocalDate() ).isNull(); |
448 | 453 |
|
449 | 454 | } |
| 455 | + |
| 456 | + |
| 457 | + |
| 458 | + |
| 459 | + |
| 460 | + |
| 461 | + |
| 462 | + @Test |
| 463 | + @WithClasses(LocalTimeToXmlGregorianCalendar.class) |
| 464 | + public void shouldMapIncompleteLocalTimeToXmlGregorianCalendar() { |
| 465 | + |
| 466 | + LocalTimeBean in = new LocalTimeBean(); |
| 467 | + LocalTime dt = new LocalTime( 1, 1, 0, 100 ); |
| 468 | + in.setLocalTime( dt ); |
| 469 | + XmlGregorianCalendarBean res = LocalTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean( in ); |
| 470 | + |
| 471 | + assertThat( res.getxMLGregorianCalendar().getYear() ).isEqualTo( DatatypeConstants.FIELD_UNDEFINED ); |
| 472 | + assertThat( res.getxMLGregorianCalendar().getMonth() ).isEqualTo( DatatypeConstants.FIELD_UNDEFINED ); |
| 473 | + assertThat( res.getxMLGregorianCalendar().getDay() ).isEqualTo( DatatypeConstants.FIELD_UNDEFINED ); |
| 474 | + assertThat( res.getxMLGregorianCalendar().getHour() ).isEqualTo( 1 ); |
| 475 | + assertThat( res.getxMLGregorianCalendar().getMinute() ).isEqualTo( 1 ); |
| 476 | + assertThat( res.getxMLGregorianCalendar().getSecond() ).isEqualTo( 0 ); |
| 477 | + assertThat( res.getxMLGregorianCalendar().getMillisecond() ).isEqualTo( 100 ); |
| 478 | + assertThat( res.getxMLGregorianCalendar().getTimezone() ).isEqualTo( DatatypeConstants.FIELD_UNDEFINED ); |
| 479 | + } |
| 480 | + |
| 481 | + @Test |
| 482 | + @WithClasses(XmlGregorianCalendarToLocalTime.class) |
| 483 | + public void shouldMapXmlGregorianCalendarToLocalTime() throws Exception { |
| 484 | + |
| 485 | + XmlGregorianCalendarBean in = new XmlGregorianCalendarBean(); |
| 486 | + XMLGregorianCalendar xcal = |
| 487 | + DatatypeFactory.newInstance().newXMLGregorianCalendarTime( 1, 1, 1, 100, 60 ); |
| 488 | + in.setxMLGregorianCalendar( xcal ); |
| 489 | + |
| 490 | + LocalTimeBean res = XmlGregorianCalendarToLocalTime.INSTANCE.toLocalTimeBean( in ); |
| 491 | + assertThat( res.getLocalTime().getHourOfDay() ).isEqualTo( 1 ); |
| 492 | + assertThat( res.getLocalTime().getMinuteOfHour() ).isEqualTo( 1 ); |
| 493 | + assertThat( res.getLocalTime().getSecondOfMinute() ).isEqualTo( 1 ); |
| 494 | + assertThat( res.getLocalTime().getMillisOfSecond() ).isEqualTo( 100 ); |
| 495 | + } |
| 496 | + |
| 497 | + @Test |
| 498 | + @WithClasses(XmlGregorianCalendarToLocalTime.class) |
| 499 | + public void shouldMapXmlGregorianCalendarWithoutMillisToLocalTime() throws Exception { |
| 500 | + |
| 501 | + XmlGregorianCalendarBean in = new XmlGregorianCalendarBean(); |
| 502 | + XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(); |
| 503 | + xcal.setHour( 23 ); |
| 504 | + xcal.setMinute( 34 ); |
| 505 | + xcal.setSecond( 45 ); |
| 506 | + in.setxMLGregorianCalendar( xcal ); |
| 507 | + |
| 508 | + LocalTimeBean res = XmlGregorianCalendarToLocalTime.INSTANCE.toLocalTimeBean( in ); |
| 509 | + assertThat( res.getLocalTime().getHourOfDay() ).isEqualTo( 23 ); |
| 510 | + assertThat( res.getLocalTime().getMinuteOfHour() ).isEqualTo( 34 ); |
| 511 | + assertThat( res.getLocalTime().getSecondOfMinute() ).isEqualTo( 45 ); |
| 512 | + assertThat( res.getLocalTime().getMillisOfSecond() ).isEqualTo( 0 ); |
| 513 | + } |
| 514 | + |
| 515 | + @Test |
| 516 | + @WithClasses(XmlGregorianCalendarToLocalTime.class) |
| 517 | + public void shouldMapXmlGregorianCalendarWithoutSecondsToLocalTime() throws Exception { |
| 518 | + |
| 519 | + XmlGregorianCalendarBean in = new XmlGregorianCalendarBean(); |
| 520 | + XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(); |
| 521 | + xcal.setHour( 23 ); |
| 522 | + xcal.setMinute( 34 ); |
| 523 | + xcal.setTimezone( 60 ); |
| 524 | + in.setxMLGregorianCalendar( xcal ); |
| 525 | + |
| 526 | + LocalTimeBean res = XmlGregorianCalendarToLocalTime.INSTANCE.toLocalTimeBean( in ); |
| 527 | + assertThat( res.getLocalTime().getHourOfDay() ).isEqualTo( 23 ); |
| 528 | + assertThat( res.getLocalTime().getMinuteOfHour() ).isEqualTo( 34 ); |
| 529 | + assertThat( res.getLocalTime().getSecondOfMinute() ).isEqualTo( 0 ); |
| 530 | + assertThat( res.getLocalTime().getMillisOfSecond() ).isEqualTo( 0 ); |
| 531 | + } |
| 532 | + |
| 533 | + @Test |
| 534 | + @WithClasses(XmlGregorianCalendarToLocalTime.class) |
| 535 | + public void shouldNotMapXmlGregorianCalendarWithoutMinutesToLocalTime() throws Exception { |
| 536 | + |
| 537 | + XmlGregorianCalendarBean in = new XmlGregorianCalendarBean(); |
| 538 | + XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(); |
| 539 | + xcal.setYear( 1999 ); |
| 540 | + xcal.setMonth( 5 ); |
| 541 | + xcal.setDay( 25 ); |
| 542 | + xcal.setHour( 23 ); |
| 543 | + in.setxMLGregorianCalendar( xcal ); |
| 544 | + |
| 545 | + LocalTimeBean res = XmlGregorianCalendarToLocalTime.INSTANCE.toLocalTimeBean( in ); |
| 546 | + assertThat( res.getLocalTime() ).isNull(); |
| 547 | + |
| 548 | + } |
| 549 | + |
450 | 550 | } |
0 commit comments