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