Search in sources :

Example 16 with ProcessorTest

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

the class SubclassMappingTest method mappingIsDoneUsingSubclassMapping.

@ProcessorTest
@WithClasses(SimpleSubclassMapper.class)
void mappingIsDoneUsingSubclassMapping() {
    VehicleCollection vehicles = new VehicleCollection();
    vehicles.getVehicles().add(new Car());
    vehicles.getVehicles().add(new Bike());
    VehicleCollectionDto result = SimpleSubclassMapper.INSTANCE.map(vehicles);
    assertThat(result.getVehicles()).doesNotContainNull();
    // remove generic so that test works.
    assertThat(result.getVehicles()).extracting(vehicle -> (Class) vehicle.getClass()).containsExactly(CarDto.class, BikeDto.class);
}
Also used : HatchBackDto(org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) Bike(org.mapstruct.ap.test.subclassmapping.mappables.Bike) Diagnostic(org.mapstruct.ap.testutil.compilation.annotation.Diagnostic) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HatchBack(org.mapstruct.ap.test.subclassmapping.mappables.HatchBack) VehicleDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto) WithClasses(org.mapstruct.ap.testutil.WithClasses) BikeDto(org.mapstruct.ap.test.subclassmapping.mappables.BikeDto) Vehicle(org.mapstruct.ap.test.subclassmapping.mappables.Vehicle) VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) IssueKey(org.mapstruct.ap.testutil.IssueKey) CarDto(org.mapstruct.ap.test.subclassmapping.mappables.CarDto) CompilationResult(org.mapstruct.ap.testutil.compilation.annotation.CompilationResult) Car(org.mapstruct.ap.test.subclassmapping.mappables.Car) ExpectedCompilationOutcome(org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome) Car(org.mapstruct.ap.test.subclassmapping.mappables.Car) VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) Bike(org.mapstruct.ap.test.subclassmapping.mappables.Bike) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 17 with ProcessorTest

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

the class SubclassMappingTest method subclassMappingOverridesInverseInheritsMapping.

@ProcessorTest
@WithClasses({ HatchBack.class, InverseOrderSubclassMapper.class })
void subclassMappingOverridesInverseInheritsMapping() {
    VehicleCollectionDto vehicleDtos = new VehicleCollectionDto();
    CarDto carDto = new CarDto();
    carDto.setMaker("BenZ");
    vehicleDtos.getVehicles().add(carDto);
    VehicleCollection result = InverseOrderSubclassMapper.INSTANCE.mapInverse(vehicleDtos);
    // remove generic so that test works.
    assertThat(result.getVehicles()).extracting(vehicle -> (Class) vehicle.getClass()).containsExactly(Car.class);
}
Also used : HatchBackDto(org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) Bike(org.mapstruct.ap.test.subclassmapping.mappables.Bike) Diagnostic(org.mapstruct.ap.testutil.compilation.annotation.Diagnostic) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HatchBack(org.mapstruct.ap.test.subclassmapping.mappables.HatchBack) VehicleDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto) WithClasses(org.mapstruct.ap.testutil.WithClasses) BikeDto(org.mapstruct.ap.test.subclassmapping.mappables.BikeDto) Vehicle(org.mapstruct.ap.test.subclassmapping.mappables.Vehicle) VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) IssueKey(org.mapstruct.ap.testutil.IssueKey) CarDto(org.mapstruct.ap.test.subclassmapping.mappables.CarDto) CompilationResult(org.mapstruct.ap.testutil.compilation.annotation.CompilationResult) Car(org.mapstruct.ap.test.subclassmapping.mappables.Car) ExpectedCompilationOutcome(org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome) VehicleCollectionDto(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto) CarDto(org.mapstruct.ap.test.subclassmapping.mappables.CarDto) VehicleCollection(org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 18 with ProcessorTest

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

the class SourceToManyTargetPropertiesTest method shouldMapSameSourcePropertyToSeveralTargetPropertiesInvokingOtherMapper.

@ProcessorTest
@IssueKey("94")
public void shouldMapSameSourcePropertyToSeveralTargetPropertiesInvokingOtherMapper() throws ParseException {
    Source source = new Source();
    String sourceFormat = "dd-MM-yyyy";
    SimpleDateFormat dateFormat = new SimpleDateFormat(sourceFormat);
    Date sourceTime = dateFormat.parse("09-01-2014");
    TimeAndFormat sourceTimeAndFormat = new TimeAndFormat();
    sourceTimeAndFormat.setTfFormat(sourceFormat);
    sourceTimeAndFormat.setTfTime(sourceTime);
    source.setTimeAndFormat(sourceTimeAndFormat);
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getFormat()).isEqualTo(sourceFormat);
    assertThat(target.getTime()).isEqualTo(sourceTime);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 19 with ProcessorTest

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

the class UnmappedSourceTest method shouldLeaveUnmappedSourcePropertyUnset.

@ProcessorTest
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
@ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, line = 20, message = "Unmapped source property: \"qux\"."), @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, line = 22, message = "Unmapped source property: \"bar\".") })
public void shouldLeaveUnmappedSourcePropertyUnset() {
    Source source = new Source();
    source.setFoo(42L);
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getFoo()).isEqualTo(42L);
    assertThat(target.getBar()).isEqualTo(0);
}
Also used : Target(org.mapstruct.ap.test.unmappedtarget.Target) Source(org.mapstruct.ap.test.unmappedtarget.Source) ExpectedCompilationOutcome(org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 20 with ProcessorTest

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

the class EnumToEnumMappingTest method shouldGenerateEnumMappingMethod.

@ProcessorTest
public void shouldGenerateEnumMappingMethod() {
    ExternalOrderType target = OrderMapper.INSTANCE.orderTypeToExternalOrderType(OrderType.B2B);
    assertThat(target).isEqualTo(ExternalOrderType.B2B);
    target = OrderMapper.INSTANCE.orderTypeToExternalOrderType(OrderType.RETAIL);
    assertThat(target).isEqualTo(ExternalOrderType.RETAIL);
}
Also used : ExternalOrderType(org.mapstruct.ap.test.value.ExternalOrderType) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

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