Search in sources :

Example 86 with WithClasses

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

the class NamedTest method shouldMatchClassAndMethod.

@ProcessorTest
@WithClasses({ Titles.class, Facts.class, PlotWords.class, OriginalRelease.class, EnglishToGerman.class, TitleTranslator.class, MovieMapper.class, KeyWordMapper.class, FactMapper.class })
public void shouldMatchClassAndMethod() {
    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);
    GermanRelease germanMovies = MovieMapper.INSTANCE.toGerman(foreignMovies);
    assertThat(germanMovies).isNotNull();
    assertThat(germanMovies.getTitle()).isEqualTo("Der sechste Sinn");
    assertThat(germanMovies.getKeyWords()).isNotNull();
    assertThat(germanMovies.getKeyWords().size()).isEqualTo(2);
    assertThat(germanMovies.getKeyWords()).containsSequence("Evergreen", "Großartig");
    assertThat(germanMovies.getFacts()).isNotNull();
    assertThat(germanMovies.getFacts()).hasSize(3);
    assertThat(germanMovies.getFacts()).contains(entry("Regisseur", Arrays.asList("M. Night Shyamalan")), entry("Besetzung", Arrays.asList("Bruce Willis", "Haley Joel Osment", "Toni Collette")), entry("Handlungstichwörter", Arrays.asList("Jungen", "Kinderpsychologe", "Ich sehe tote Menschen")));
}
Also used : GermanRelease(org.mapstruct.ap.test.selection.qualifier.bean.GermanRelease) CreateGermanRelease(org.mapstruct.ap.test.selection.qualifier.annotation.CreateGermanRelease) OriginalRelease(org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease) HashMap(java.util.HashMap) List(java.util.List) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 87 with WithClasses

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

the class ConversionTest method shouldApplyGenericTypeMapper.

@ProcessorTest
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
public void shouldApplyGenericTypeMapper() {
    // setup used types
    TypeB typeB = new TypeB();
    // setup source
    Source source = new Source();
    source.setFooInteger(new Wrapper<>(5));
    source.setFooString(new Wrapper<>("test"));
    source.setFooStringArray(new Wrapper<>(new String[] { "test1", "test2" }));
    source.setFooLongArray(new ArrayWrapper<>(new Long[] { 5L, 3L }));
    source.setFooTwoArgs(new TwoArgWrapper<>(new TwoArgHolder<>(3, true)));
    source.setFooNested(new Wrapper<>(new Wrapper<>(new BigDecimal(5))));
    source.setFooUpperBoundCorrect(new UpperBoundWrapper<>(typeB));
    source.setFooWildCardExtendsString(new WildCardExtendsWrapper<>("test3"));
    source.setFooWildCardSuperString(new WildCardSuperWrapper<>("test4"));
    source.setFooWildCardSuperTypeBCorrect(new WildCardSuperWrapper<>(typeB));
    // define wrapper
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    // assert results
    assertThat(target).isNotNull();
    assertThat(target.getFooInteger()).isEqualTo(5);
    assertThat(target.getFooString()).isEqualTo("test");
    assertThat(target.getFooStringArray()).isEqualTo(new String[] { "test1", "test2" });
    assertThat(target.getFooLongArray()).isEqualTo(new Long[] { 5L, 3L });
    assertThat(target.getFooTwoArgs().getArg1()).isEqualTo(3);
    assertThat(target.getFooTwoArgs().getArg2()).isEqualTo(true);
    assertThat(target.getFooNested()).isEqualTo(new BigDecimal(5));
    assertThat(target.getFooUpperBoundCorrect()).isEqualTo(typeB);
    assertThat(target.getFooWildCardExtendsString()).isEqualTo("test3");
    assertThat(target.getFooWildCardSuperString()).isEqualTo("test4");
    assertThat(target.getFooWildCardSuperTypeBCorrect()).isEqualTo(typeB);
}
Also used : BigDecimal(java.math.BigDecimal) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 88 with WithClasses

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

the class JodaTimeTest method shouldMapXmlGregorianCalendarToDateTime.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldMapXmlGregorianCalendarToDateTime() throws Exception {
    XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
    XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(2010, 1, 15, 1, 1, 1, 100, 60);
    in.setxMLGregorianCalendar(xcal);
    DateTimeBean res = XmlGregorianCalendarToDateTime.INSTANCE.toDateTimeBean(in);
    assertThat(res.getDateTime().getYear()).isEqualTo(2010);
    assertThat(res.getDateTime().getMonthOfYear()).isEqualTo(1);
    assertThat(res.getDateTime().getDayOfMonth()).isEqualTo(15);
    assertThat(res.getDateTime().getHourOfDay()).isEqualTo(1);
    assertThat(res.getDateTime().getMinuteOfHour()).isEqualTo(1);
    assertThat(res.getDateTime().getSecondOfMinute()).isEqualTo(1);
    assertThat(res.getDateTime().getMillisOfSecond()).isEqualTo(100);
    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 89 with WithClasses

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

the class JodaTimeTest method shouldMapXmlGregorianCalendarWithoutTimeZoneToDateTimeWithDefaultTimeZone.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldMapXmlGregorianCalendarWithoutTimeZoneToDateTimeWithDefaultTimeZone() 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);
    xcal.setMillisecond(500);
    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(45);
    assertThat(res.getDateTime().getMillisOfSecond()).isEqualTo(500);
    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 90 with WithClasses

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

the class JodaTimeTest method shouldNotMapXmlGregorianCalendarWithoutMinutes.

@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldNotMapXmlGregorianCalendarWithoutMinutes() 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);
    DateTimeBean res = XmlGregorianCalendarToDateTime.INSTANCE.toDateTimeBean(in);
    assertThat(res.getDateTime()).isNull();
}
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)

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