#2124 Add extra test case

This commit is contained in:
Filip Hrisafov 2020-06-21 23:24:56 +02:00
parent ef3cbc1b36
commit bdc58b9602
3 changed files with 88 additions and 0 deletions

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._2124;
/**
* @author Filip Hrisafov
*/
public class CommitComment {
private final Integer issueId;
public CommitComment(Integer issueId) {
this.issueId = issueId;
}
public Integer getIssueId() {
return issueId;
}
}

View File

@ -0,0 +1,28 @@
/*
* 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._2124;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
/**
* @author Filip Hrisafov
*/
@Mapper
public interface Issue2124Mapper {
Issue2124Mapper INSTANCE = Mappers.getMapper( Issue2124Mapper.class );
@Mapping(target = "issueId", source = "comment.issueId", qualifiedByName = "mapped")
CommitComment clone(CommitComment comment, String otherSource);
@Named("mapped")
default Integer mapIssueNumber(int issueNumber) {
return issueNumber * 2;
}
}

View File

@ -0,0 +1,38 @@
/*
* 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._2124;
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 Filip Hrisafov
*/
@IssueKey("2124")
@RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({
CommitComment.class,
Issue2124Mapper.class
})
public class Issue2124Test {
@Test
public void shouldCompile() {
CommitComment clone = Issue2124Mapper.INSTANCE.clone( new CommitComment( 100 ), null );
assertThat( clone ).isNotNull();
assertThat( clone.getIssueId() ).isEqualTo( 200 );
clone = Issue2124Mapper.INSTANCE.clone( new CommitComment( null ), null );
assertThat( clone ).isNotNull();
assertThat( clone.getIssueId() ).isNull();
}
}