use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class DecoratorTest method shouldApplyCustomMappers.
@IssueKey("173")
@ProcessorTest
@WithClasses({ Person2Mapper.class, Person2MapperDecorator.class, Person2.class, PersonDto2.class, Employer.class, EmployerDto.class, EmployerMapper.class, SportsClub.class, SportsClubDto.class })
public void shouldApplyCustomMappers() {
// given
Calendar birthday = Calendar.getInstance();
birthday.set(1928, Calendar.MAY, 23);
Person2 person = new Person2("Gary", "Crant", birthday.getTime(), new Address("42 Ocean View Drive"));
person.setEmployer(new Employer("ACME"));
person.setSportsClub(new SportsClub("SC Duckburg"));
// when
PersonDto2 personDto = Person2Mapper.INSTANCE.personToPersonDto(person);
// then
assertThat(personDto).isNotNull();
assertThat(personDto.getName()).isEqualTo("Gary Crant");
assertThat(personDto.getAddress()).isNotNull();
assertThat(personDto.getAddress().getAddressLine()).isEqualTo("42 Ocean View Drive");
assertThat(personDto.getEmployer()).isNotNull();
assertThat(personDto.getEmployer().getName()).isNotNull();
assertThat(personDto.getEmployer().getName()).isEqualTo("ACME");
assertThat(personDto.getSportsClub()).isNotNull();
assertThat(personDto.getSportsClub().getName()).isNotNull();
assertThat(personDto.getSportsClub().getName()).isEqualTo("SC Duckburg");
}
use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.
the class DecoratorTest method shouldInvokeDecoratorMethods.
@ProcessorTest
@WithClasses({ PersonMapper.class, PersonMapperDecorator.class })
public void shouldInvokeDecoratorMethods() {
// given
Calendar birthday = Calendar.getInstance();
birthday.set(1928, Calendar.MAY, 23);
Person person = new Person("Gary", "Crant", birthday.getTime(), new Address("42 Ocean View Drive"));
// when
PersonDto personDto = PersonMapper.INSTANCE.personToPersonDto(person);
// then
assertThat(personDto).isNotNull();
assertThat(personDto.getName()).isEqualTo("Gary Crant");
assertThat(personDto.getAddress()).isNotNull();
assertThat(personDto.getAddress().getAddressLine()).isEqualTo("42 Ocean View Drive");
}
use of org.mapstruct.ap.testutil.WithClasses 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.WithClasses 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.WithClasses 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);
}
Aggregations