#1790 Use mapperPrism.values.nullValuePropertyMappingStrategy when retrieving NullValuePropertyMappingStrategy

This commit is contained in:
Filip Hrisafov 2019-09-18 13:09:40 +02:00 committed by GitHub
parent 447bb00f89
commit d018aed251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 123 additions and 1 deletions

View File

@ -192,7 +192,7 @@ public class MapperConfiguration {
else if ( beanPrism != null ) {
return beanPrism;
}
else if ( mapperConfigPrism != null && mapperPrism.values.nullValueCheckStrategy() == null ) {
else if ( mapperConfigPrism != null && mapperPrism.values.nullValuePropertyMappingStrategy() == null ) {
return NullValuePropertyMappingStrategyPrism.valueOf(
mapperConfigPrism.nullValuePropertyMappingStrategy()
);

View File

@ -0,0 +1,16 @@
/*
* 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._1790;
import org.mapstruct.MapperConfig;
import org.mapstruct.NullValueCheckStrategy;
/**
* @author Filip Hrisafov
*/
@MapperConfig(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface Issue1790Config {
}

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._1790;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.factory.Mappers;
/**
* @author Filip Hrisafov
*/
@Mapper(config = Issue1790Config.class, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface Issue1790Mapper {
Issue1790Mapper INSTANCE = Mappers.getMapper( Issue1790Mapper.class );
void toExistingCar(@MappingTarget Target target, Source source);
}

View File

@ -0,0 +1,40 @@
/*
* 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._1790;
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("1790")
@RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({
Issue1790Config.class,
Issue1790Mapper.class,
Source.class,
Target.class,
})
public class Issue1790Test {
@Test
public void shouldProperlyApplyNullValuePropertyMappingStrategyWhenInheriting() {
Target target = new Target();
target.setName( "My name is set" );
Source source = new Source();
Issue1790Mapper.INSTANCE.toExistingCar( target, source );
assertThat( target.getName() ).isEqualTo( "My name is set" );
}
}

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._1790;
/**
* @author Filip Hrisafov
*/
public class Source {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

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._1790;
/**
* @author Filip Hrisafov
*/
public class Target {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}