#2795: use 'includeModel' for the 'sourcePresenceCheckerReference' in the 'UpdateWrapper'. (#2796)

* #2795: use 'includeModel' for the 'sourcePresenceCheckerReference' in the 'UpdateWrapper'.
* Simplify the tests

Co-authored-by: Ben Zegveld <Ben.Zegveld@gmail.com>
Co-authored-by: Filip Hrisafov <filip.hrisafov@gmail.com>
This commit is contained in:
Zegveld 2022-04-02 18:55:06 +02:00 committed by GitHub
parent 2473c3eaaa
commit 03d44b5a87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 138 additions and 1 deletions

View File

@ -10,7 +10,7 @@
<@lib.handleExceptions>
<#if includeSourceNullCheck>
<@lib.sourceLocalVarAssignment/>
if ( <#if sourcePresenceCheckerReference?? >${sourcePresenceCheckerReference}<#else><#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference}</#if> != null</#if> ) {
if ( <#if sourcePresenceCheckerReference?? ><@includeModel object=sourcePresenceCheckerReference /><#else><#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference}</#if> != null</#if> ) {
<@assignToExistingTarget/>
<@lib.handleAssignment/>;
}

View File

@ -0,0 +1,30 @@
/*
* 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._2795;
import java.util.Optional;
import org.mapstruct.Condition;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
@Mapper
public interface Issue2795Mapper {
void update(Source update, @MappingTarget Target destination);
void update(NestedDto update, @MappingTarget Nested destination);
static <T> T unwrap(Optional<T> optional) {
return optional.orElse( null );
}
@Condition
static <T> boolean isNotEmpty(Optional<T> field) {
return field != null && field.isPresent();
}
}

View File

@ -0,0 +1,25 @@
/*
* 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._2795;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
@IssueKey("2795")
@WithClasses({
Issue2795Mapper.class,
Nested.class,
NestedDto.class,
Target.class,
Source.class,
})
public class Issue2795Test {
@ProcessorTest
void shouldCompile() {
}
}

View File

@ -0,0 +1,20 @@
/*
* 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._2795;
public class Nested {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,20 @@
/*
* 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._2795;
public class NestedDto {
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._2795;
import java.util.Optional;
public class Source {
private Optional<NestedDto> nested = Optional.empty();
public Optional<NestedDto> getNested() {
return nested;
}
public void setNested(Optional<NestedDto> nested) {
this.nested = nested;
}
}

View File

@ -0,0 +1,20 @@
/*
* 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._2795;
public class Target {
private Nested nested;
public Nested getNested() {
return nested;
}
public void setNested(Nested nested) {
this.nested = nested;
}
}