mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#2501 Add test case
This commit is contained in:
parent
1bf698785c
commit
c5c292f602
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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._2501;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface Issue2501Mapper {
|
||||||
|
|
||||||
|
Issue2501Mapper INSTANCE = Mappers.getMapper( Issue2501Mapper.class );
|
||||||
|
|
||||||
|
Customer map(CustomerDTO value);
|
||||||
|
|
||||||
|
CustomerStatus map(DtoStatus status);
|
||||||
|
|
||||||
|
default <T> T unwrap(Optional<T> optional) {
|
||||||
|
return optional.orElse( null );
|
||||||
|
}
|
||||||
|
|
||||||
|
enum CustomerStatus {
|
||||||
|
ENABLED, DISABLED,
|
||||||
|
}
|
||||||
|
|
||||||
|
class Customer {
|
||||||
|
|
||||||
|
private CustomerStatus status;
|
||||||
|
|
||||||
|
public CustomerStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(CustomerStatus stat) {
|
||||||
|
this.status = stat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DtoStatus {
|
||||||
|
ENABLED, DISABLED
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomerDTO {
|
||||||
|
|
||||||
|
private DtoStatus status;
|
||||||
|
|
||||||
|
public Optional<DtoStatus> getStatus() {
|
||||||
|
return Optional.ofNullable( status );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(DtoStatus stat) {
|
||||||
|
this.status = stat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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._2501;
|
||||||
|
|
||||||
|
import org.mapstruct.ap.testutil.ProcessorTest;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@WithClasses({
|
||||||
|
Issue2501Mapper.class
|
||||||
|
})
|
||||||
|
class Issue2501Test {
|
||||||
|
|
||||||
|
@ProcessorTest
|
||||||
|
void shouldUnwrapEnumOptional() {
|
||||||
|
Issue2501Mapper.CustomerDTO source = new Issue2501Mapper.CustomerDTO();
|
||||||
|
source.setStatus( Issue2501Mapper.DtoStatus.DISABLED );
|
||||||
|
|
||||||
|
Issue2501Mapper.Customer target = Issue2501Mapper.INSTANCE.map( source );
|
||||||
|
|
||||||
|
assertThat( target.getStatus() ).isEqualTo( Issue2501Mapper.CustomerStatus.DISABLED );
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user