Search in sources :

Example 51 with WithClasses

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

the class CompilingStatement method getTestClasses.

/**
 * Returns the classes to be compiled for this test.
 *
 * @return A set containing the classes to be compiled for this test
 */
private Set<Class<?>> getTestClasses() {
    Set<Class<?>> testClasses = new HashSet<Class<?>>();
    WithClasses withClasses = method.getAnnotation(WithClasses.class);
    if (withClasses != null) {
        testClasses.addAll(Arrays.asList(withClasses.value()));
    }
    withClasses = method.getMethod().getDeclaringClass().getAnnotation(WithClasses.class);
    if (withClasses != null) {
        testClasses.addAll(Arrays.asList(withClasses.value()));
    }
    if (testClasses.isEmpty()) {
        throw new IllegalStateException("The classes to be compiled during the test must be specified via @WithClasses.");
    }
    return testClasses;
}
Also used : WithClasses(org.mapstruct.ap.testutil.WithClasses) HashSet(java.util.HashSet)

Example 52 with WithClasses

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

the class Issue1482Test method testForward.

@ProcessorTest
@WithClasses(SourceTargetMapper.class)
public void testForward() {
    Source source = new Source();
    source.setTest(SourceEnum.VAL1);
    source.setWrapper(new BigDecimalWrapper(new BigDecimal(5)));
    Target target = SourceTargetMapper.INSTANCE.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getTest()).isEqualTo("value1");
    assertThat(target.getBigDecimal()).isEqualTo(new BigDecimal(5));
}
Also used : BigDecimal(java.math.BigDecimal) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 53 with WithClasses

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

the class BuiltInTest method shouldApplyBuiltInOnIterable.

@ProcessorTest
@WithClasses(IterableSourceTargetMapper.class)
public void shouldApplyBuiltInOnIterable() throws DatatypeConfigurationException {
    IterableSource source = new IterableSource();
    source.setDates(Arrays.asList(createXmlCal(1999, 3, 2, 60)));
    source.publicDates = Arrays.asList(createXmlCal(2016, 3, 2, 60));
    IterableTarget target = IterableSourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getDates()).containsExactly("02.03.1999");
    assertThat(target.publicDates).containsExactly("02.03.2016");
}
Also used : IterableSource(org.mapstruct.ap.test.builtin.source.IterableSource) IterableTarget(org.mapstruct.ap.test.builtin._target.IterableTarget) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 54 with WithClasses

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

the class BuiltInTest method shouldApplyBuiltInOnDateToXmlGregCal.

@ProcessorTest
@WithClasses(DateToXmlGregCalMapper.class)
public void shouldApplyBuiltInOnDateToXmlGregCal() throws ParseException {
    DateProperty source = new DateProperty();
    source.setProp(createDate("31-08-1982 10:20:56"));
    source.publicProp = createDate("31-08-2016 10:20:56");
    XmlGregorianCalendarProperty target = DateToXmlGregCalMapper.INSTANCE.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getProp()).isNotNull();
    assertThat(target.getProp().toString()).isEqualTo("1982-08-31T10:20:56.000+02:00");
    assertThat(target.publicProp).isNotNull();
    assertThat(target.publicProp.toString()).isEqualTo("2016-08-31T10:20:56.000+02:00");
}
Also used : XmlGregorianCalendarProperty(org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty) DateProperty(org.mapstruct.ap.test.builtin.bean.DateProperty) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 55 with WithClasses

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

the class BuiltInTest method shouldApplyBuiltInOnCalendarToXmlGregCal.

@ProcessorTest
@WithClasses(CalendarToXmlGregCalMapper.class)
public void shouldApplyBuiltInOnCalendarToXmlGregCal() throws ParseException {
    CalendarProperty source = new CalendarProperty();
    source.setProp(createCalendar("02.03.1999"));
    source.publicProp = createCalendar("02.03.2016");
    XmlGregorianCalendarProperty target = CalendarToXmlGregCalMapper.INSTANCE.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getProp()).isNotNull();
    assertThat(target.getProp().toString()).isEqualTo("1999-03-02T00:00:00.000+01:00");
    assertThat(target.publicProp).isNotNull();
    assertThat(target.publicProp.toString()).isEqualTo("2016-03-02T00:00:00.000+01:00");
}
Also used : XmlGregorianCalendarProperty(org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty) CalendarProperty(org.mapstruct.ap.test.builtin.bean.CalendarProperty) XmlGregorianCalendarProperty(org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty) 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