#644 Add more elaborate test case for inheritance with generics with multiple overlapping interfaces

This commit is contained in:
Andreas Gudian 2015-11-09 22:52:03 +01:00
parent e4bbfdaaa6
commit 874a9b3a52
14 changed files with 504 additions and 2 deletions

View File

@ -0,0 +1,23 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
public abstract class AbstractClassExposingItemB
implements ItemProviderAny<ItemB>, ItemProviderSomeItemA<ItemA> {
}

View File

@ -0,0 +1,27 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
/**
* @author Andreas Gudian
*/
public abstract class AbstractClassExposingItemC
implements ItemProviderSomeItemA<ItemB>, ItemProviderSomeItemB<ItemC> {
}

View File

@ -0,0 +1,56 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;
/**
* @author Andreas Gudian
*
*/
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class GenericsHierarchyMapper {
public static final GenericsHierarchyMapper INSTANCE = Mappers.getMapper( GenericsHierarchyMapper.class );
@Mapping(target = "itemC", source = "item")
public abstract Target toTarget(AbstractClassExposingItemC source);
@Mapping(target = "itemB", source = "item")
public abstract Target toTarget(AbstractClassExposingItemB source);
@Mapping(target = "item", source = "itemC")
public abstract void intoSourceWithItemC(Target target, @MappingTarget AbstractClassExposingItemC bean);
@Mapping(target = "item", source = "itemB")
public abstract void intoSourceWithItemB(Target target, @MappingTarget AbstractClassExposingItemB bean);
protected ItemC modifyItemC(ItemC item) {
item.setTypeParameterIsResolvedToItemC( true );
return item;
}
protected ItemB modifyItemB(ItemB item) {
item.setTypeParameterIsResolvedToItemB( true );
return item;
}
}

View File

@ -0,0 +1,99 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
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.fest.assertions.Assertions.assertThat;
/**
* @author Andreas Gudian
*
*/
@RunWith(AnnotationProcessorTestRunner.class)
@IssueKey("644,687,688")
@WithClasses({
AbstractClassExposingItemC.class,
AbstractClassExposingItemB.class,
GenericsHierarchyMapper.class,
ItemA.class,
ItemB.class,
ItemC.class,
ItemProviderSomeItemA.class,
ItemProviderAny.class,
ItemProviderSomeItemB.class,
Target.class
})
public class GenericsHierarchyTest {
@Test
public void determinesItemCSourceGetter() {
AbstractClassExposingItemC source = new SourceWithItemC();
source.setItem( new ItemC() );
// make sure the jdk compiler resolves the same as we expect
source.getItem().setTypeParameterIsResolvedToItemC( false );
Target target = GenericsHierarchyMapper.INSTANCE.toTarget( source );
assertThat( target.getItemC().typeParameterIsResolvedToItemC() ).isTrue();
assertThat( target.getItemC().typeParameterIsResolvedToItemB() ).isFalse();
}
@Test
public void determinesItemBSourceGetter() {
AbstractClassExposingItemB source = new SourceWithItemB();
source.setItem( new ItemB() );
// make sure the jdk compiler resolves the same as we expect
source.getItem().setTypeParameterIsResolvedToItemB( false );
Target target = GenericsHierarchyMapper.INSTANCE.toTarget( source );
assertThat( target.getItemB().typeParameterIsResolvedToItemB() ).isTrue();
}
@Test
public void determinesItemCSourceSetter() {
Target target = new Target();
target.setItemC( new ItemC() );
SourceWithItemC source = new SourceWithItemC();
GenericsHierarchyMapper.INSTANCE.intoSourceWithItemC( target, source );
assertThat( source.getItem().typeParameterIsResolvedToItemC() ).isTrue();
}
@Test
public void determinesItemBSourceSetter() {
Target target = new Target();
target.setItemB( new ItemB() );
SourceWithItemB source = new SourceWithItemB();
GenericsHierarchyMapper.INSTANCE.intoSourceWithItemB( target, source );
assertThat( source.getItem().typeParameterIsResolvedToItemB() ).isTrue();
}
}

View File

@ -0,0 +1,27 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
/**
* @author Andreas Gudian
*
*/
public class ItemA {
}

View File

@ -0,0 +1,35 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
/**
* @author Andreas Gudian
*
*/
public class ItemB extends ItemA {
private boolean typeParameterIsResolvedToItemB;
public boolean typeParameterIsResolvedToItemB() {
return typeParameterIsResolvedToItemB;
}
public void setTypeParameterIsResolvedToItemB(boolean typeParameterIsResolvedToItemB) {
this.typeParameterIsResolvedToItemB = typeParameterIsResolvedToItemB;
}
}

View File

@ -0,0 +1,35 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
/**
* @author Andreas Gudian
*
*/
public class ItemC extends ItemB {
private boolean typeParameterIsResolvedToItemC;
public boolean typeParameterIsResolvedToItemC() {
return typeParameterIsResolvedToItemC;
}
public void setTypeParameterIsResolvedToItemC(boolean typeParameterIsResolvedToItemC) {
this.typeParameterIsResolvedToItemC = typeParameterIsResolvedToItemC;
}
}

View File

@ -0,0 +1,28 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
/**
* @author Andreas Gudian
*/
public interface ItemProviderAny<X> {
X getItem();
void setItem(X id);
}

View File

@ -0,0 +1,26 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
/**
* @author Andreas Gudian
*/
public interface ItemProviderSomeItemA<T extends ItemA> {
T getItem();
}

View File

@ -0,0 +1,29 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
/**
* @author Andreas Gudian
*/
public interface ItemProviderSomeItemB<ID extends ItemB> extends ItemProviderSomeItemA<ItemB> {
@Override
ID getItem();
void setItem(ID item);
}

View File

@ -0,0 +1,35 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
/**
* @author Andreas Gudian
*
*/
public class SourceWithItemB extends AbstractClassExposingItemB {
private ItemB item;
public ItemB getItem() {
return item;
}
public void setItem(ItemB item) {
this.item = item;
}
}

View File

@ -0,0 +1,37 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
/**
* @author Andreas Gudian
*
*/
public class SourceWithItemC extends AbstractClassExposingItemC {
private ItemC item;
@Override
public ItemC getItem() {
return item;
}
@Override
public void setItem(ItemC item) {
this.item = item;
}
}

View File

@ -0,0 +1,45 @@
/**
* Copyright 2012-2015 Gunnar Morling (http://www.gunnarmorling.de/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.test.abstractclass.generics;
/**
* @author Andreas Gudian
*
*/
public class Target {
private ItemC itemC;
private ItemB itemB;
public ItemC getItemC() {
return itemC;
}
public void setItemC(ItemC itemC) {
this.itemC = itemC;
}
public ItemB getItemB() {
return itemB;
}
public void setItemB(ItemB itemB) {
this.itemB = itemB;
}
}

View File

@ -55,8 +55,8 @@ class EclipseCompilingStatement extends CompilingStatement {
config.setAnnotationProcessors( new String[] { MappingProcessor.class.getName() } );
config.setSourceFiles( getSourceFiles( compilationRequest.getSourceClasses() ) );
config.setShowWarnings( false );
config.setSourceVersion( "1.6" );
config.setTargetVersion( "1.6" );
config.setSourceVersion( "1.8" );
config.setTargetVersion( "1.8" );
for ( String option : compilationRequest.getProcessorOptions() ) {
config.addCompilerCustomArgument( option, null );