#1648 Source properties defined in Mapping should not be reported as unmapped

This commit is contained in:
Filip Hrisafov 2018-11-18 10:11:11 +01:00 committed by GitHub
parent b651ad34b5
commit a3ba57c372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 105 additions and 0 deletions

View File

@ -486,6 +486,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
.nullValuePropertyMappingStrategy( mapping.getNullValuePropertyMappingStrategy() )
.build();
handledTargets.add( propertyName );
unprocessedSourceProperties.remove( mapping.getSourceName() );
unprocessedSourceParameters.remove( sourceRef.getParameter() );
}
else {

View File

@ -0,0 +1,23 @@
/*
* 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._1648;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;
/**
* @author Filip Hrisafov
*/
@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR)
public interface Issue1648Mapper {
Issue1648Mapper INSTANCE = Mappers.getMapper( Issue1648Mapper.class );
@Mapping(target = "targetValue", source = "sourceValue")
Target map(Source source);
}

View File

@ -0,0 +1,37 @@
/*
* 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._1648;
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
*/
@IssueKey("1648")
@RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({
Issue1648Mapper.class,
Source.class,
Target.class,
})
public class Issue1648Test {
@Test
public void shouldCorrectlyMarkSourceAsUsed() {
Source source = new Source();
source.setSourceValue( "value" );
Target target = Issue1648Mapper.INSTANCE.map( source );
assertThat( target.getTargetValue() ).isEqualTo( "value" );
}
}

View File

@ -0,0 +1,22 @@
/*
* 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._1648;
/**
* @author Filip Hrisafov
*/
public class Source {
private String sourceValue;
public String getSourceValue() {
return sourceValue;
}
public void setSourceValue(String sourceValue) {
this.sourceValue = sourceValue;
}
}

View File

@ -0,0 +1,22 @@
/*
* 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._1648;
/**
* @author Filip Hrisafov
*/
public class Target {
private String targetValue;
public String getTargetValue() {
return targetValue;
}
public void setTargetValue(String targetValue) {
this.targetValue = targetValue;
}
}