Search in sources :

Example 26 with WithClasses

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

the class JodaTimeTest method shouldMapLocalDateToXmlGregorianCalendar.

@ProcessorTest
@WithClasses(LocalDateToXmlGregorianCalendar.class)
public void shouldMapLocalDateToXmlGregorianCalendar() {
    LocalDateBean in = new LocalDateBean();
    LocalDate dt = new LocalDate(2010, 1, 15);
    in.setLocalDate(dt);
    XmlGregorianCalendarBean res = LocalDateToXmlGregorianCalendar.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(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getMinute()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getSecond()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getMillisecond()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
    assertThat(res.getxMLGregorianCalendar().getTimezone()).isEqualTo(DatatypeConstants.FIELD_UNDEFINED);
}
Also used : LocalDateBean(org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateBean) XmlGregorianCalendarBean(org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean) LocalDate(org.joda.time.LocalDate) XmlGregorianCalendarToLocalDate(org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDate) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 27 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses 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 28 with WithClasses

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

the class JodaTimeTest method shouldMapXmlGregorianCalendarWithoutSecondsToDateTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldMapXmlGregorianCalendarWithoutSecondsToDateTime() 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.setTimezone(60);
    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(null)).isEqualTo(3600000);
}
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 29 with WithClasses

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

the class NamedTest method testFactorySelectionWithQualifier.

@ProcessorTest
@WithClasses({ MovieFactoryMapper.class, ReleaseFactory.class, CreateGermanRelease.class })
@IssueKey("342")
public void testFactorySelectionWithQualifier() {
    OriginalRelease foreignMovies = new OriginalRelease();
    foreignMovies.setTitle("Sixth Sense, The");
    foreignMovies.setKeyWords(Arrays.asList("evergreen", "magnificent"));
    Map<String, List<String>> facts = new HashMap<>();
    facts.put("director", Arrays.asList("M. Night Shyamalan"));
    facts.put("cast", Arrays.asList("Bruce Willis", "Haley Joel Osment", "Toni Collette"));
    facts.put("plot keywords", Arrays.asList("boy", "child psychologist", "I see dead people"));
    foreignMovies.setFacts(facts);
    AbstractEntry abstractEntry = MovieFactoryMapper.INSTANCE.toGerman(foreignMovies);
    assertThat(abstractEntry).isNotNull();
    assertThat(abstractEntry).isInstanceOf(GermanRelease.class);
    assertThat(abstractEntry.getTitle()).isEqualTo("Sixth Sense, The");
    assertThat(abstractEntry.getKeyWords()).isNotNull();
    assertThat(abstractEntry.getKeyWords().size()).isEqualTo(2);
    assertThat(abstractEntry.getKeyWords()).containsSequence("evergreen", "magnificent");
    assertThat(abstractEntry.getFacts()).isNotNull();
    assertThat(abstractEntry.getFacts()).hasSize(3);
    assertThat(abstractEntry.getFacts()).contains(entry("director", Arrays.asList("M. Night Shyamalan")), entry("cast", Arrays.asList("Bruce Willis", "Haley Joel Osment", "Toni Collette")), entry("plot keywords", Arrays.asList("boy", "child psychologist", "I see dead people")));
}
Also used : AbstractEntry(org.mapstruct.ap.test.selection.qualifier.bean.AbstractEntry) OriginalRelease(org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease) HashMap(java.util.HashMap) List(java.util.List) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 30 with WithClasses

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

the class JavaDefaultExpressionTest method testJavaDefaultExpressionWithValues.

@ProcessorTest
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
public void testJavaDefaultExpressionWithValues() {
    Source source = new Source();
    source.setId(123);
    source.setDate(new Date(0L));
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getSourceId()).isEqualTo("123");
    assertThat(target.getSourceDate()).isEqualTo(source.getDate());
}
Also used : Date(java.util.Date) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

WithClasses (org.mapstruct.ap.testutil.WithClasses)119 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)118 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)17 IssueKey (org.mapstruct.ap.testutil.IssueKey)17 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)11 DateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean)10 CalendarProperty (org.mapstruct.ap.test.builtin.bean.CalendarProperty)8 Song (org.mapstruct.ap.test.constructor.nestedsource.source.Song)8 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)7 BigDecimal (java.math.BigDecimal)6 BigInteger (java.math.BigInteger)6 ChartEntry (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry)6 Date (java.util.Date)5 LocalDateTime (org.joda.time.LocalDateTime)5 StringProperty (org.mapstruct.ap.test.builtin.bean.StringProperty)5 XmlGregorianCalendarToLocalDateTime (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime)5 VehicleCollection (org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection)5