#853 Minor adjustments after review

This commit is contained in:
Andreas Gudian 2016-09-21 22:30:47 +02:00
parent 1be3c4dbaa
commit f822000f92
5 changed files with 16 additions and 19 deletions

View File

@ -253,7 +253,7 @@ public class IterableMappingMethod extends MappingMethod {
return sourceParameterType.getComponentType();
}
else {
return sourceParameterType.determineTypeArguments( Iterable.class ).get( 0 ).getTypeBound();
return first( sourceParameterType.determineTypeArguments( Iterable.class ) ).getTypeBound();
}
}
@ -262,7 +262,7 @@ public class IterableMappingMethod extends MappingMethod {
return getResultType().getComponentType();
}
else {
return getResultType().determineTypeArguments( Iterable.class ).get( 0 );
return first( getResultType().determineTypeArguments( Iterable.class ) );
}
}

View File

@ -798,10 +798,7 @@ public class Type extends ModelElement implements Comparable<Type> {
* @return a list of type arguments or null, if superclass was not found
*/
public List<Type> determineTypeArguments(Class<?> superclass) {
TypeMirror superclassMirror =
typeUtils.erasure( elementUtils.getTypeElement( superclass.getCanonicalName() ).asType() );
if ( typeUtils.isAssignable( superclassMirror, typeMirror )
&& typeUtils.isAssignable( typeMirror, superclassMirror ) ) {
if ( qualifiedName.equals( superclass.getName() ) ) {
return getTypeParameters();
}

View File

@ -19,6 +19,7 @@
package org.mapstruct.ap.test.collection;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import java.util.ArrayList;
import java.util.Arrays;
@ -29,7 +30,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.fest.assertions.MapAssert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey;
@ -37,7 +37,7 @@ import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
@WithClasses({ Source.class, Target.class, Colour.class, SourceTargetMapper.class, TestList.class, TestMap.class,
TestNonGenericList.class, StringToLongMap.class })
StringArrayList.class, StringToLongMap.class })
@RunWith(AnnotationProcessorTestRunner.class)
public class CollectionMappingTest {
@ -393,7 +393,7 @@ public class CollectionMappingTest {
}
@Test
@IssueKey("TODO")
@IssueKey("853")
public void shouldMapNonGenericList() {
Source source = new Source();
source.setStringList3( new ArrayList<String>( Arrays.asList( "Bob", "Alice" ) ) );
@ -405,7 +405,7 @@ public class CollectionMappingTest {
// Inverse direction
Target newTarget = new Target();
TestNonGenericList nonGenericStringList = new TestNonGenericList();
StringArrayList nonGenericStringList = new StringArrayList();
nonGenericStringList.addAll( Arrays.asList( "Bill", "Bob" ) );
newTarget.setNonGenericStringList( nonGenericStringList );
@ -416,7 +416,7 @@ public class CollectionMappingTest {
}
@Test
@IssueKey("TODO")
@IssueKey("853")
public void shouldMapNonGenericMap() {
Source source = new Source();
Map<String, Long> map = new HashMap<String, Long>();
@ -427,8 +427,7 @@ public class CollectionMappingTest {
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
assertThat( target ).isNotNull();
assertThat( target.getNonGenericMapStringtoLong() ).includes( MapAssert.entry( "Bob", 123L ),
MapAssert.entry( "Alice", 456L ) );
assertThat( target.getNonGenericMapStringtoLong() ).contains( entry( "Bob", 123L ), entry( "Alice", 456L ) );
// Inverse direction
Target newTarget = new Target();
@ -440,7 +439,8 @@ public class CollectionMappingTest {
Source mappedSource = SourceTargetMapper.INSTANCE.targetToSource( newTarget );
assertThat( mappedSource ).isNotNull();
assertThat( mappedSource.getStringLongMapForNonGeneric() ).includes( MapAssert.entry( "Blue", 321L ),
MapAssert.entry( "Green", 654L ) );
assertThat( mappedSource.getStringLongMapForNonGeneric() ).contains(
entry( "Blue", 321L ),
entry( "Green", 654L ) );
}
}

View File

@ -23,7 +23,7 @@ import java.util.ArrayList;
/**
* @author Stefan May
*/
public class TestNonGenericList extends ArrayList<String> {
public class StringArrayList extends ArrayList<String> {
private static final long serialVersionUID = 1L;
}

View File

@ -58,7 +58,7 @@ public class Target {
private EnumSet<Colour> enumSet;
private TestNonGenericList nonGenericStringList;
private StringArrayList nonGenericStringList;
private StringToLongMap nonGenericMapStringtoLong;
@ -189,11 +189,11 @@ public class Target {
this.enumSet = enumSet;
}
public TestNonGenericList getNonGenericStringList() {
public StringArrayList getNonGenericStringList() {
return nonGenericStringList;
}
public void setNonGenericStringList(TestNonGenericList nonGenericStringList) {
public void setNonGenericStringList(StringArrayList nonGenericStringList) {
this.nonGenericStringList = nonGenericStringList;
}