use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class JodaTimeTest method shouldMapRoundTrip.
@ProcessorTest
@WithClasses({ DateTimeToXmlGregorianCalendar.class, XmlGregorianCalendarToDateTime.class })
public void shouldMapRoundTrip() {
DateTimeBean dtb1 = new DateTimeBean();
DateTime dt = new DateTime(2010, 1, 15, 1, 1, 1, 100, DateTimeZone.forOffsetHours(-1));
dtb1.setDateTime(dt);
XmlGregorianCalendarBean xcb1 = DateTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean(dtb1);
DateTimeBean dtb2 = XmlGregorianCalendarToDateTime.INSTANCE.toDateTimeBean(xcb1);
XmlGregorianCalendarBean xcb2 = DateTimeToXmlGregorianCalendar.INSTANCE.toXmlGregorianCalendarBean(dtb2);
assertThat(dtb1.getDateTime()).isEqualTo(dtb2.getDateTime());
assertThat(xcb1.getxMLGregorianCalendar()).isEqualTo(xcb2.getxMLGregorianCalendar());
}
use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class JodaTimeTest method shouldMapXmlGregorianCalendarWithoutMillisToDateTime.
@ProcessorTest
@WithClasses(XmlGregorianCalendarToDateTime.class)
public void shouldMapXmlGregorianCalendarWithoutMillisToDateTime() 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.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(45);
assertThat(res.getDateTime().getMillisOfSecond()).isEqualTo(0);
assertThat(res.getDateTime().getZone().getOffset(null)).isEqualTo(3600000);
}
use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class JodaTimeTest method shouldMapXmlGregorianCalendarToLocalDate.
@ProcessorTest
@WithClasses(XmlGregorianCalendarToLocalDate.class)
public void shouldMapXmlGregorianCalendarToLocalDate() throws Exception {
XmlGregorianCalendarBean in = new XmlGregorianCalendarBean();
XMLGregorianCalendar xcal = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(1999, 5, 25, DatatypeConstants.FIELD_UNDEFINED);
in.setxMLGregorianCalendar(xcal);
LocalDateBean res = XmlGregorianCalendarToLocalDate.INSTANCE.toLocalDateBean(in);
assertThat(res.getLocalDate().getYear()).isEqualTo(1999);
assertThat(res.getLocalDate().getMonthOfYear()).isEqualTo(5);
assertThat(res.getLocalDate().getDayOfMonth()).isEqualTo(25);
}
use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class MultipleBuilderMapperTest method builderMappingDefined.
@WithClasses({ BuilderDefinedMapper.class })
@ProcessorTest
public void builderMappingDefined() {
Process map = BuilderDefinedMapper.INSTANCE.map(new Source("map"));
Process wrongMap = BuilderDefinedMapper.INSTANCE.wrongMap(new Source("wrongMap"));
assertThat(map.getBuildMethod()).isEqualTo("create");
assertThat(wrongMap.getBuildMethod()).isEqualTo("wrongCreate");
}
use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class MultipleBuilderMapperTest method tooManyBuilderCreationMethods.
@WithClasses({ TooManyBuilderCreationMethodsMapper.class })
@ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @Diagnostic(type = Case.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 11, message = "More than one builder creation method for \"org.mapstruct.ap.test.builder.multiple.builder" + ".Case\". Found methods: \"wrongBuilder(), builder()\". Builder will not be used. Consider " + "implementing a custom BuilderProvider SPI.") })
@ProcessorTest
public void tooManyBuilderCreationMethods() {
Case caseTarget = TooManyBuilderCreationMethodsMapper.INSTANCE.map(new Source("test"));
assertThat(caseTarget).isNotNull();
assertThat(caseTarget.getName()).isEqualTo("test");
assertThat(caseTarget.getBuilderCreationMethod()).isNull();
assertThat(caseTarget.getBuildMethod()).isEqualTo("constructor");
}
Aggregations