#1590 ArrayList missing as import for NVMS.RETURN_DEFAULT (#1598)

This commit is contained in:
Sjaak Derksen 2018-08-29 21:11:22 +02:00 committed by GitHub
parent ded8d88c73
commit bd2c206f7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 115 additions and 0 deletions

View File

@ -63,6 +63,9 @@ public class SetterWrapperForCollectionsAndMapsWithNullCheck extends WrapperForC
if (isDirectAssignment() || getSourcePresenceCheckerReference() == null ) {
imported.addAll( getNullCheckLocalVarType().getImportTypes() );
}
if ( isMapNullToDefault() && ( targetType.getImplementationType() != null ) ) {
imported.add( targetType.getImplementationType() );
}
return imported;
}

View File

@ -0,0 +1,9 @@
/*
* 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._1590;
public class Book {
}

View File

@ -0,0 +1,21 @@
/*
* 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._1590;
import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface BookMapper {
BookMapper INSTANCE = Mappers.getMapper( BookMapper.class );
Book map(Book book);
List<Book> map(List<Book> books);
}

View File

@ -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._1590;
import java.util.List;
public class BookShelf {
private List<Book> books;
public List<Book> getBooks() {
return books;
}
public void setBooks(List<Book> books) {
this.books = books;
}
}

View File

@ -0,0 +1,21 @@
/*
* 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._1590;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValueMappingStrategy;
import org.mapstruct.factory.Mappers;
@Mapper(uses = BookMapper.class,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface BookShelfMapper {
BookShelfMapper INSTANCE = Mappers.getMapper( BookShelfMapper.class );
BookShelf map(BookShelf bookShelf);
}

View File

@ -0,0 +1,41 @@
/*
* 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._1590;
import java.util.Arrays;
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
*/
@WithClasses({
BookMapper.class,
BookShelfMapper.class,
Book.class,
BookShelf.class
})
@RunWith(AnnotationProcessorTestRunner.class)
@IssueKey("1590")
public class Issue1590Test {
@Test
public void shouldTestMappingLocalDates() {
BookShelf source = new BookShelf();
source.setBooks( Arrays.asList( new Book() ) );
BookShelf target = BookShelfMapper.INSTANCE.map( source );
assertThat( target ).isNotNull();
assertThat( target.getBooks() ).isNotNull();
}
}