#1594 Add test case to show that it has been fixed

This commit is contained in:
Filip Hrisafov 2018-10-12 23:57:24 +02:00
parent f17ddcfb18
commit 0e0fd313e5
2 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,84 @@
/*
* 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._1594;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
/**
* @author Filip Hrisafov
*/
@Mapper
public interface Issue1594Mapper {
Issue1594Mapper INSTANCE = Mappers.getMapper( Issue1594Mapper.class );
@Mappings({
@Mapping(target = "address.country.oid", expression = "java(dto.getFullAddress().split( \"-\" )[0])"),
@Mapping(target = "address.city.oid", expression = "java(dto.getFullAddress().split( \"-\" )[1])"),
})
Client toClient(Dto dto);
class Client {
private Address address;
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
class Address {
private Id country;
private Id city;
public Id getCountry() {
return country;
}
public void setCountry(Id country) {
this.country = country;
}
public Id getCity() {
return city;
}
public void setCity(Id city) {
this.city = city;
}
}
class Id {
private String oid;
public String getOid() {
return oid;
}
public void setOid(String oid) {
this.oid = oid;
}
}
class Dto {
private String fullAddress;
public String getFullAddress() {
return fullAddress;
}
public void setFullAddress(String fullAddress) {
this.fullAddress = fullAddress;
}
}
}

View File

@ -0,0 +1,41 @@
/*
* 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._1594;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Filip Hrisafov
*/
@RunWith(AnnotationProcessorTestRunner.class)
@IssueKey("1594")
@WithClasses({
Issue1594Mapper.class
})
public class Issue1594Test {
@Test
public void shouldGenerateCorrectMapping() {
Issue1594Mapper.Dto dto = new Issue1594Mapper.Dto();
dto.setFullAddress( "Switzerland-Zurich" );
Issue1594Mapper.Client client = Issue1594Mapper.INSTANCE.toClient( dto );
assertThat( client ).isNotNull();
assertThat( client.getAddress() ).isNotNull();
assertThat( client.getAddress().getCountry() ).isNotNull();
assertThat( client.getAddress().getCountry().getOid() ).isEqualTo( "Switzerland" );
assertThat( client.getAddress().getCity() ).isNotNull();
assertThat( client.getAddress().getCity().getOid() ).isEqualTo( "Zurich" );
}
}