Reproducal for #2421

This commit is contained in:
Filip Hrisafov 2021-04-24 22:01:54 +02:00
parent 627be53088
commit 488d95121f
5 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,29 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2421;
public class Company {
private String name;
private CompanyType companyType;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public CompanyType getCompanyType() {
return companyType;
}
public void setCompanyType(CompanyType companyType) {
this.companyType = companyType;
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2421;
public class CompanyDto {
private String name;
private String companyType;
private String companyTypeLatinTitle;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCompanyType() {
return companyType;
}
public void setCompanyType(String companyType) {
this.companyType = companyType;
}
public String getCompanyTypeLatinTitle() {
return companyTypeLatinTitle;
}
public void setCompanyTypeLatinTitle(String companyTypeLatinTitle) {
this.companyTypeLatinTitle = companyTypeLatinTitle;
}
}

View File

@ -0,0 +1,24 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2421;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface CompanyMapper {
CompanyMapper INSTANCE = Mappers.getMapper( CompanyMapper.class );
@Mapping(target = "companyTypeLatinTitle", source = "companyType.latinTitle")
CompanyDto toDto(Company entity);
@InheritInverseConfiguration
@Mapping( target = "companyType", source = "companyType")
Company toEntity(CompanyDto dto);
}

View File

@ -0,0 +1,28 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2421;
public enum CompanyType {
insurance("Insurance", "insurance"),
inspection("Inspection", "inspectionem"),
Shipping("Shipping", "naviportans");
private final String title;
private final String latinTitle;
CompanyType(String title, String latinTitle) {
this.title = title;
this.latinTitle = latinTitle;
}
public String getTitle() {
return title;
}
public String getLatinTitle() {
return latinTitle;
}
}

View File

@ -0,0 +1,38 @@
package org.mapstruct.ap.test.bugs._2421;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Filip Hrisafov
*/
@IssueKey("2421")
@WithClasses({
Company.class,
CompanyDto.class,
CompanyMapper.class,
CompanyType.class
})
public class Issue2421Test {
@ProcessorTest
public void shouldGenerateValidCode() {
Company entity = new Company();
entity.setName( "Test" );
entity.setCompanyType( CompanyType.inspection );
CompanyDto dto = CompanyMapper.INSTANCE.toDto( entity );
assertThat( dto.getName() ).isEqualTo( "Test" );
assertThat( dto.getCompanyType() ).isEqualTo( "inspection" );
assertThat( dto.getCompanyTypeLatinTitle() ).isEqualTo( "inspectionem" );
entity = CompanyMapper.INSTANCE.toEntity( dto );
assertThat( entity.getName() ).isEqualTo( "Test" );
assertThat( entity.getCompanyType() ).isEqualTo( CompanyType.inspection );
}
}