#1933 ignoreByDefault not inherited from config (#1935)

This commit is contained in:
Sjaak Derksen 2019-10-05 15:47:25 +02:00 committed by GitHub
parent b3023b3902
commit 1cb8291fb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 102 additions and 4 deletions

View File

@ -55,7 +55,7 @@ public class BeanMapping {
beanMapping.nullValuePropertyMappingStrategy,
beanMapping.nullValueCheckStrategy,
beanMapping.reportingPolicy,
false,
beanMapping.ignoreByDefault,
beanMapping.ignoreUnmappedSourceProperties,
beanMapping.builder,
beanMapping.mirror

View File

@ -0,0 +1,35 @@
/*
* 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._1933;
import org.mapstruct.BeanMapping;
import org.mapstruct.MapperConfig;
import org.mapstruct.MappingInheritanceStrategy;
/**
* @author Sjaak Derksen
*/
@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG)
public interface Issue1933Config {
@BeanMapping(ignoreByDefault = true)
Entity updateEntity(Dto dto);
class Entity {
//CHECKSTYLE:OFF
public String id;
public int updateCount;
//CHECKSTYLE:ON
}
class Dto {
//CHECKSTYLE:OFF
public String id;
public int updateCount;
//CHECKSTYLE:ON
}
}

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._1933;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
/**
* @author Sjaak Derksen
*/
@Mapper(config = Issue1933Config.class)
public interface Issue1933Mapper {
Issue1933Mapper INSTANCE = Mappers.getMapper( Issue1933Mapper.class );
@Mapping(target = "updateCount", source = "updateCount")
Issue1933Config.Entity map(Issue1933Config.Dto dto);
}

View File

@ -0,0 +1,39 @@
/*
* 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._1933;
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 Sjaak Derksen
*/
@IssueKey("1933")
@RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({
Issue1933Config.class,
Issue1933Mapper.class
})
public class Issue1933Test {
@Test
public void shouldIgnoreIdAndMapUpdateCount() {
Issue1933Config.Dto dto = new Issue1933Config.Dto();
dto.id = "id";
dto.updateCount = 5;
Issue1933Config.Entity entity = Issue1933Mapper.INSTANCE.map( dto );
assertThat( entity.id ).isNull();
assertThat( entity.updateCount ).isEqualTo( 5 );
}
}

View File

@ -20,6 +20,7 @@ public interface BuilderIgnoringMapper {
BuilderIgnoringMapper INSTANCE = Mappers.getMapper( BuilderIgnoringMapper.class );
@InheritConfiguration(name = "mapBase")
@Mapping( target = "lastName" )
Person mapWithIgnoringBase(PersonDto source);
@BeanMapping(ignoreByDefault = true)

View File

@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BuilderIgnoringTest {
@Test
@IssueKey( "1933" )
public void shouldIgnoreBase() {
PersonDto source = new PersonDto();
source.setId( 100L );
@ -38,7 +39,7 @@ public class BuilderIgnoringTest {
Person target = BuilderIgnoringMapper.INSTANCE.mapWithIgnoringBase( source );
assertThat( target.getId() ).isNull();
assertThat( target.getName() ).isEqualTo( "John" );
assertThat( target.getName() ).isNull();
assertThat( target.getLastName() ).isEqualTo( "Doe" );
}

View File

@ -55,7 +55,7 @@ public class IgnorePropertyTest {
}
@Test
@IssueKey("1392")
@IssueKey("1933")
public void shouldIgnoreBase() {
WorkBenchDto workBenchDto = new WorkBenchDto();
@ -67,7 +67,7 @@ public class IgnorePropertyTest {
WorkBenchEntity benchTarget = ToolMapper.INSTANCE.mapBench( workBenchDto );
assertThat( benchTarget ).isNotNull();
assertThat( benchTarget.getArticleName() ).isEqualTo( "MyBench" );
assertThat( benchTarget.getArticleName() ).isNull();
assertThat( benchTarget.getDescription() ).isEqualTo( "Beautiful" );
assertThat( benchTarget.getKey() ).isNull();
assertThat( benchTarget.getModificationDate() ).isNull();