#1966 extra unit test (#1967)

This commit is contained in:
Sjaak Derksen 2019-11-10 20:14:33 +01:00 committed by GitHub
parent b26cd4e0cb
commit 071e5dc6b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,55 @@
/*
* 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._1966;
import java.util.Collections;
import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.factory.Mappers;
/**
* @author Sjaak Derksen
*/
@Mapper( imports = Collections.class )
public interface Issue1966Mapper {
Issue1966Mapper INSTANCE = Mappers.getMapper( Issue1966Mapper.class );
@Mapping(target = "previousNames",
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
defaultExpression = "java(Collections.emptyList())")
Animal toAnimal(AnimalRecord record);
class AnimalRecord {
private String[] previousNames;
public String[] getPreviousNames() {
return previousNames;
}
public void setPreviousNames(String[] previousNames) {
this.previousNames = previousNames;
}
}
class Animal {
private List<String> previousNames;
public List<String> getPreviousNames() {
return previousNames;
}
public void setPreviousNames(List<String> previousNames) {
this.previousNames = previousNames;
}
}
}

View File

@ -0,0 +1,36 @@
/*
* 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._1966;
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 Sjaak Derksen
*/
@IssueKey("1966")
@RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({
Issue1966Mapper.class
})
public class Issue1966Test {
@Test
public void shouldSelectDefaultExpressionEvenWhenSourceInMappingIsNotSpecified() {
Issue1966Mapper.AnimalRecord dto = new Issue1966Mapper.AnimalRecord();
Issue1966Mapper.Animal entity = Issue1966Mapper.INSTANCE.toAnimal( dto );
assertThat( entity.getPreviousNames() ).isNotNull();
assertThat( entity.getPreviousNames() ).isEmpty();
}
}