mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
* #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:
parent
2473c3eaaa
commit
03d44b5a87
@ -10,7 +10,7 @@
|
|||||||
<@lib.handleExceptions>
|
<@lib.handleExceptions>
|
||||||
<#if includeSourceNullCheck>
|
<#if includeSourceNullCheck>
|
||||||
<@lib.sourceLocalVarAssignment/>
|
<@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/>
|
<@assignToExistingTarget/>
|
||||||
<@lib.handleAssignment/>;
|
<@lib.handleAssignment/>;
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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() {
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user