Skip to content

Commit

Permalink
mapstruct#1790 Use mapperPrism.values.nullValuePropertyMappingStrateg…
Browse files Browse the repository at this point in the history
…y when retrieving NullValuePropertyMappingStrategy
  • Loading branch information
filiphr committed Sep 18, 2019
1 parent 447bb00 commit d018aed
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 1 deletion.
Expand Up @@ -192,7 +192,7 @@ public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy
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()
);
Expand Down
@@ -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 {
}
@@ -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);
}
@@ -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" );
}
}
@@ -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;
}
}
@@ -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;
}
}

0 comments on commit d018aed

Please sign in to comment.