mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#765 Omitting "return" key word when returning from decorated void method
This commit is contained in:
parent
ab159ed86a
commit
9753fdc17a
@ -20,7 +20,7 @@
|
|||||||
-->
|
-->
|
||||||
@Override
|
@Override
|
||||||
public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>) <@throws/> {
|
public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>) <@throws/> {
|
||||||
return delegate.${name}( <#list parameters as param>${param.name}<#if param_has_next>, </#if></#list> );
|
<#if returnType.name != "void">return </#if>delegate.${name}( <#list parameters as param>${param.name}<#if param_has_next>, </#if></#list> );
|
||||||
}
|
}
|
||||||
<#macro throws>
|
<#macro throws>
|
||||||
<@compress single_line=true>
|
<@compress single_line=true>
|
||||||
|
@ -22,6 +22,13 @@ public class AddressDto {
|
|||||||
|
|
||||||
private String addressLine;
|
private String addressLine;
|
||||||
|
|
||||||
|
public AddressDto() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddressDto(String addressLine) {
|
||||||
|
this.addressLine = addressLine;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAddressLine() {
|
public String getAddressLine() {
|
||||||
return addressLine;
|
return addressLine;
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,24 @@ public class DecoratorTest {
|
|||||||
assertThat( addressDto.getAddressLine() ).isEqualTo( "42 Ocean View Drive" );
|
assertThat( addressDto.getAddressLine() ).isEqualTo( "42 Ocean View Drive" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithClasses({
|
||||||
|
PersonMapper.class,
|
||||||
|
PersonMapperDecorator.class
|
||||||
|
})
|
||||||
|
@IssueKey("765")
|
||||||
|
public void shouldDelegateNonDecoratedVoidMethodsToDefaultImplementation() {
|
||||||
|
//given
|
||||||
|
AddressDto addressDto = new AddressDto( "42 Ocean View Drive" );
|
||||||
|
|
||||||
|
//when
|
||||||
|
Address address = new Address( "Main Street" );
|
||||||
|
PersonMapper.INSTANCE.updateAddressFromDto( addressDto, address );
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat( address.getAddressLine() ).isEqualTo( "42 Ocean View Drive" );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithClasses({
|
@WithClasses({
|
||||||
AnotherPersonMapper.class,
|
AnotherPersonMapper.class,
|
||||||
|
@ -21,6 +21,7 @@ package org.mapstruct.ap.test.decorator;
|
|||||||
import org.mapstruct.DecoratedWith;
|
import org.mapstruct.DecoratedWith;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.MappingTarget;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
@ -33,4 +34,6 @@ public interface PersonMapper {
|
|||||||
PersonDto personToPersonDto(Person person);
|
PersonDto personToPersonDto(Person person);
|
||||||
|
|
||||||
AddressDto addressToAddressDto(Address address);
|
AddressDto addressToAddressDto(Address address);
|
||||||
|
|
||||||
|
void updateAddressFromDto(AddressDto dto, @MappingTarget Address address);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user