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