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")));
}
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);
}
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);
}
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));
}
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();
}
Aggregations