Search in sources :

Example 31 with ProcessorTest

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

the class Issue1569Test method shouldGenerateCorrectMapping.

@ProcessorTest
public void shouldGenerateCorrectMapping() {
    Source source = new Source();
    Date date = Date.from(LocalDate.of(2018, Month.AUGUST, 5).atTime(20, 30).toInstant(ZoneOffset.UTC));
    source.setPromotionDate(date);
    Target target = Issue1569Mapper.INSTANCE.map(source);
    assertThat(target.getPromotionDate()).isEqualTo(LocalDate.of(2018, Month.AUGUST, 5));
}
Also used : Date(java.util.Date) LocalDate(java.time.LocalDate) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 32 with ProcessorTest

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

the class Issue1269Test method shouldMapNestedPropertiesCorrectly.

@ProcessorTest
public void shouldMapNestedPropertiesCorrectly() {
    VehicleTypeInfo sourceTypeInfo = new VehicleTypeInfo("Opel", "Corsa", 3);
    List<VehicleImage> sourceImages = Arrays.asList(new VehicleImage(100, "something"), new VehicleImage(150, "somethingElse"));
    Vehicle source = new Vehicle(sourceTypeInfo, sourceImages);
    VehicleDto target = VehicleMapper.INSTANCE.map(source);
    assertThat(target.getVehicleInfo()).isNotNull();
    assertThat(target.getVehicleInfo().getDoors()).isEqualTo(3);
    assertThat(target.getVehicleInfo().getType()).isEqualTo("Opel");
    assertThat(target.getVehicleInfo().getName()).isEqualTo("Corsa");
    assertThat(target.getVehicleInfo().getImages()).hasSize(2);
    assertThat(target.getVehicleInfo().getImages().get(0)).isEqualToComparingFieldByField(sourceImages.get(0));
    assertThat(target.getVehicleInfo().getImages().get(1)).isEqualToComparingFieldByField(sourceImages.get(1));
}
Also used : Vehicle(org.mapstruct.ap.test.bugs._1269.model.Vehicle) VehicleDto(org.mapstruct.ap.test.bugs._1269.dto.VehicleDto) VehicleImage(org.mapstruct.ap.test.bugs._1269.model.VehicleImage) VehicleTypeInfo(org.mapstruct.ap.test.bugs._1269.model.VehicleTypeInfo) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 33 with ProcessorTest

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

the class Issue1124Test method nestedPropertyWithContextCompiles.

@ProcessorTest
public void nestedPropertyWithContextCompiles() {
    Entity entity = new Entity();
    Entity subEntity = new Entity();
    subEntity.setId(42L);
    entity.setEntity(subEntity);
    DTO dto = Mappers.getMapper(Issue1124Mapper.class).map(entity, new MappingContext());
    assertThat(dto.getId()).isEqualTo(42L);
}
Also used : MappingContext(org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.MappingContext) Entity(org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.Entity) DTO(org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.DTO) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 34 with ProcessorTest

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

the class BuiltInTest method shouldApplyBuiltInStringToXmlGregCal.

@ProcessorTest
@WithClasses(StringToXmlGregCalMapper.class)
public void shouldApplyBuiltInStringToXmlGregCal() {
    StringProperty source = new StringProperty();
    source.setProp("05.07.1999");
    source.publicProp = "05.07.2016";
    XmlGregorianCalendarProperty target = StringToXmlGregCalMapper.INSTANCE.mapAndFormat(source);
    assertThat(target).isNotNull();
    assertThat(target.getProp()).isNotNull();
    assertThat(target.getProp().toString()).isEqualTo("1999-07-05T00:00:00.000+02:00");
    assertThat(target.publicProp).isNotNull();
    assertThat(target.publicProp.toString()).isEqualTo("2016-07-05T00:00:00.000+02:00");
    // direct,via lexical representation
    source.setProp("2000-03-04T23:00:00+03:00");
    source.publicProp = "2016-03-04T23:00:00+03:00";
    target = StringToXmlGregCalMapper.INSTANCE.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getProp()).isNotNull();
    assertThat(target.getProp().toString()).isEqualTo("2000-03-04T23:00:00+03:00");
    assertThat(target.publicProp).isNotNull();
    assertThat(target.publicProp.toString()).isEqualTo("2016-03-04T23:00:00+03:00");
    // null string
    source.setProp(null);
    source.publicProp = null;
    target = StringToXmlGregCalMapper.INSTANCE.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getProp()).isNull();
    assertThat(target.publicProp).isNull();
}
Also used : XmlGregorianCalendarProperty(org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty) StringProperty(org.mapstruct.ap.test.builtin.bean.StringProperty) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 35 with ProcessorTest

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

the class BuiltInTest method shouldApplyBuiltInOnXmlGregCalToCalendar.

@ProcessorTest
@WithClasses(XmlGregCalToCalendarMapper.class)
public void shouldApplyBuiltInOnXmlGregCalToCalendar() throws DatatypeConfigurationException {
    XmlGregorianCalendarProperty source = new XmlGregorianCalendarProperty();
    source.setProp(createXmlCal(1999, 3, 2, 60));
    source.publicProp = createXmlCal(2016, 3, 2, 60);
    CalendarProperty target = XmlGregCalToCalendarMapper.INSTANCE.map(source);
    assertThat(target).isNotNull();
    assertThat(target.getProp()).isNotNull();
    assertThat(target.getProp().getTimeInMillis()).isEqualTo(920329200000L);
    assertThat(target.publicProp).isNotNull();
    assertThat(target.publicProp.getTimeInMillis()).isEqualTo(1456873200000L);
    assertThat(target.publicProp.getTimeInMillis()).isEqualTo(1456873200000L);
}
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

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)314 WithClasses (org.mapstruct.ap.testutil.WithClasses)118 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)51 IssueKey (org.mapstruct.ap.testutil.IssueKey)39 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)22 Date (java.util.Date)16 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 Calendar (java.util.Calendar)13 LocalDateTime (org.joda.time.LocalDateTime)13 CarDto (org.mapstruct.ap.test.complex._target.CarDto)13 Car (org.mapstruct.ap.test.complex.source.Car)13 PersonDto (org.mapstruct.ap.test.constructor.PersonDto)13 GregorianCalendar (java.util.GregorianCalendar)12 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)12 BigDecimal (java.math.BigDecimal)11 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)11 DriverAndCarDto (org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto)11 DateTime (org.joda.time.DateTime)10