#693 Renaming test entities in generics test for the sake of easier understanding

This commit is contained in:
Gunnar Morling 2015-12-17 23:43:40 +01:00
parent 55b74ae384
commit c59ef3ab7a
13 changed files with 86 additions and 87 deletions

View File

@ -21,7 +21,7 @@ package org.mapstruct.ap.test.abstractclass.generics;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*/ */
public abstract class AbstractClassExposingItemC public abstract class AbstractAnimal
implements ItemProviderSomeItemA<ItemB>, ItemProviderSomeItemB<ItemC> { implements Identifiable<KeyOfAllBeings>, IAnimal<AnimalKey> {
} }

View File

@ -18,6 +18,6 @@
*/ */
package org.mapstruct.ap.test.abstractclass.generics; package org.mapstruct.ap.test.abstractclass.generics;
public abstract class AbstractClassExposingItemB public abstract class AbstractHuman
implements ItemProviderAny<ItemB>, ItemProviderSomeItemA<ItemA> { implements GenericIdentifiable<KeyOfAllBeings>, Identifiable<Key> {
} }

View File

@ -22,14 +22,14 @@ package org.mapstruct.ap.test.abstractclass.generics;
* @author Andreas Gudian * @author Andreas Gudian
* *
*/ */
public class ItemC extends ItemB { public class AnimalKey extends KeyOfAllBeings {
private boolean typeParameterIsResolvedToItemC; private boolean typeParameterIsResolvedToAnimalKey;
public boolean typeParameterIsResolvedToItemC() { public boolean typeParameterIsResolvedToAnimalKey() {
return typeParameterIsResolvedToItemC; return typeParameterIsResolvedToAnimalKey;
} }
public void setTypeParameterIsResolvedToItemC(boolean typeParameterIsResolvedToItemC) { public void setTypeParameterIsResolvedToAnimalKey(boolean typeParameterIsResolvedToAnimalKey) {
this.typeParameterIsResolvedToItemC = typeParameterIsResolvedToItemC; this.typeParameterIsResolvedToAnimalKey = typeParameterIsResolvedToAnimalKey;
} }
} }

View File

@ -22,14 +22,14 @@ package org.mapstruct.ap.test.abstractclass.generics;
* @author Andreas Gudian * @author Andreas Gudian
* *
*/ */
public class SourceWithItemB extends AbstractClassExposingItemB { public class Child extends AbstractHuman {
private ItemB item; private KeyOfAllBeings key;
public ItemB getItem() { public KeyOfAllBeings getKey() {
return item; return key;
} }
public void setItem(ItemB item) { public void setKey(KeyOfAllBeings key) {
this.item = item; this.key = key;
} }
} }

View File

@ -22,16 +22,16 @@ package org.mapstruct.ap.test.abstractclass.generics;
* @author Andreas Gudian * @author Andreas Gudian
* *
*/ */
public class SourceWithItemC extends AbstractClassExposingItemC { public class Elephant extends AbstractAnimal {
private ItemC item; private AnimalKey key;
@Override @Override
public ItemC getItem() { public AnimalKey getKey() {
return item; return key;
} }
@Override @Override
public void setItem(ItemC item) { public void setKey(AnimalKey key) {
this.item = item; this.key = key;
} }
} }

View File

@ -21,8 +21,8 @@ package org.mapstruct.ap.test.abstractclass.generics;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*/ */
public interface ItemProviderAny<X> { public interface GenericIdentifiable<X> {
X getItem(); X getKey();
void setItem(X id); void setKey(X id);
} }

View File

@ -32,25 +32,25 @@ import org.mapstruct.factory.Mappers;
public abstract class GenericsHierarchyMapper { public abstract class GenericsHierarchyMapper {
public static final GenericsHierarchyMapper INSTANCE = Mappers.getMapper( GenericsHierarchyMapper.class ); public static final GenericsHierarchyMapper INSTANCE = Mappers.getMapper( GenericsHierarchyMapper.class );
@Mapping(target = "itemC", source = "item") @Mapping(target = "animalKey", source = "key")
public abstract Target toTarget(AbstractClassExposingItemC source); public abstract Target toTarget(AbstractAnimal source);
@Mapping(target = "itemB", source = "item") @Mapping(target = "keyOfAllBeings", source = "key")
public abstract Target toTarget(AbstractClassExposingItemB source); public abstract Target toTarget(AbstractHuman source);
@Mapping(target = "item", source = "itemC") @Mapping(target = "key", source = "animalKey")
public abstract void intoSourceWithItemC(Target target, @MappingTarget AbstractClassExposingItemC bean); public abstract void updateSourceWithAnimalKey(Target target, @MappingTarget AbstractAnimal bean);
@Mapping(target = "item", source = "itemB") @Mapping(target = "key", source = "keyOfAllBeings")
public abstract void intoSourceWithItemB(Target target, @MappingTarget AbstractClassExposingItemB bean); public abstract void updateSourceWithKeyOfAllBeings(Target target, @MappingTarget AbstractHuman bean);
protected ItemC modifyItemC(ItemC item) { protected AnimalKey modifyAnimalKey(AnimalKey item) {
item.setTypeParameterIsResolvedToItemC( true ); item.setTypeParameterIsResolvedToAnimalKey( true );
return item; return item;
} }
protected ItemB modifyItemB(ItemB item) { protected KeyOfAllBeings modifyKeyOfAllBeings(KeyOfAllBeings item) {
item.setTypeParameterIsResolvedToItemB( true ); item.setTypeParameterIsResolvedToKeyOfAllBeings( true );
return item; return item;
} }
} }

View File

@ -33,67 +33,67 @@ import static org.fest.assertions.Assertions.assertThat;
@RunWith(AnnotationProcessorTestRunner.class) @RunWith(AnnotationProcessorTestRunner.class)
@IssueKey("644,687,688") @IssueKey("644,687,688")
@WithClasses({ @WithClasses({
AbstractClassExposingItemC.class, AbstractAnimal.class,
AbstractClassExposingItemB.class, AbstractHuman.class,
GenericsHierarchyMapper.class, GenericsHierarchyMapper.class,
ItemA.class, Key.class,
ItemB.class, KeyOfAllBeings.class,
ItemC.class, AnimalKey.class,
ItemProviderSomeItemA.class, Identifiable.class,
ItemProviderAny.class, GenericIdentifiable.class,
ItemProviderSomeItemB.class, IAnimal.class,
Target.class Target.class
}) })
public class GenericsHierarchyTest { public class GenericsHierarchyTest {
@Test @Test
public void determinesItemCSourceGetter() { public void determinesAnimalKeyGetter() {
AbstractClassExposingItemC source = new SourceWithItemC(); AbstractAnimal source = new Elephant();
source.setItem( new ItemC() ); source.setKey( new AnimalKey() );
// make sure the jdk compiler resolves the same as we expect // make sure the jdk compiler resolves the same as we expect
source.getItem().setTypeParameterIsResolvedToItemC( false ); source.getKey().setTypeParameterIsResolvedToAnimalKey( false );
Target target = GenericsHierarchyMapper.INSTANCE.toTarget( source ); Target target = GenericsHierarchyMapper.INSTANCE.toTarget( source );
assertThat( target.getItemC().typeParameterIsResolvedToItemC() ).isTrue(); assertThat( target.getAnimalKey().typeParameterIsResolvedToAnimalKey() ).isTrue();
assertThat( target.getItemC().typeParameterIsResolvedToItemB() ).isFalse(); assertThat( target.getAnimalKey().typeParameterIsResolvedToKeyOfAllBeings() ).isFalse();
} }
@Test @Test
public void determinesItemBSourceGetter() { public void determinesKeyOfAllBeingsGetter() {
AbstractClassExposingItemB source = new SourceWithItemB(); AbstractHuman source = new Child();
source.setItem( new ItemB() ); source.setKey( new KeyOfAllBeings() );
// make sure the jdk compiler resolves the same as we expect // make sure the jdk compiler resolves the same as we expect
source.getItem().setTypeParameterIsResolvedToItemB( false ); source.getKey().setTypeParameterIsResolvedToKeyOfAllBeings( false );
Target target = GenericsHierarchyMapper.INSTANCE.toTarget( source ); Target target = GenericsHierarchyMapper.INSTANCE.toTarget( source );
assertThat( target.getItemB().typeParameterIsResolvedToItemB() ).isTrue(); assertThat( target.getKeyOfAllBeings().typeParameterIsResolvedToKeyOfAllBeings() ).isTrue();
} }
@Test @Test
public void determinesItemCSourceSetter() { public void determinesItemCSourceSetter() {
Target target = new Target(); Target target = new Target();
target.setItemC( new ItemC() ); target.setAnimalKey( new AnimalKey() );
SourceWithItemC source = new SourceWithItemC(); Elephant source = new Elephant();
GenericsHierarchyMapper.INSTANCE.intoSourceWithItemC( target, source ); GenericsHierarchyMapper.INSTANCE.updateSourceWithAnimalKey( target, source );
assertThat( source.getItem().typeParameterIsResolvedToItemC() ).isTrue(); assertThat( source.getKey().typeParameterIsResolvedToAnimalKey() ).isTrue();
} }
@Test @Test
public void determinesItemBSourceSetter() { public void determinesItemBSourceSetter() {
Target target = new Target(); Target target = new Target();
target.setItemB( new ItemB() ); target.setKeyOfAllBeings( new KeyOfAllBeings() );
SourceWithItemB source = new SourceWithItemB(); Child source = new Child();
GenericsHierarchyMapper.INSTANCE.intoSourceWithItemB( target, source ); GenericsHierarchyMapper.INSTANCE.updateSourceWithKeyOfAllBeings( target, source );
assertThat( source.getItem().typeParameterIsResolvedToItemB() ).isTrue(); assertThat( source.getKey().typeParameterIsResolvedToKeyOfAllBeings() ).isTrue();
} }
} }

View File

@ -21,9 +21,9 @@ package org.mapstruct.ap.test.abstractclass.generics;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*/ */
public interface ItemProviderSomeItemB<ID extends ItemB> extends ItemProviderSomeItemA<ItemB> { public interface IAnimal<ID extends KeyOfAllBeings> extends Identifiable<KeyOfAllBeings> {
@Override @Override
ID getItem(); ID getKey();
void setItem(ID item); void setKey(ID item);
} }

View File

@ -21,6 +21,6 @@ package org.mapstruct.ap.test.abstractclass.generics;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*/ */
public interface ItemProviderSomeItemA<T extends ItemA> { public interface Identifiable<T extends Key> {
T getItem(); T getKey();
} }

View File

@ -22,6 +22,6 @@ package org.mapstruct.ap.test.abstractclass.generics;
* @author Andreas Gudian * @author Andreas Gudian
* *
*/ */
public class ItemA { public class Key {
} }

View File

@ -22,14 +22,14 @@ package org.mapstruct.ap.test.abstractclass.generics;
* @author Andreas Gudian * @author Andreas Gudian
* *
*/ */
public class ItemB extends ItemA { public class KeyOfAllBeings extends Key {
private boolean typeParameterIsResolvedToItemB; private boolean typeParameterIsResolvedToKeyOfAllBeings;
public boolean typeParameterIsResolvedToItemB() { public boolean typeParameterIsResolvedToKeyOfAllBeings() {
return typeParameterIsResolvedToItemB; return typeParameterIsResolvedToKeyOfAllBeings;
} }
public void setTypeParameterIsResolvedToItemB(boolean typeParameterIsResolvedToItemB) { public void setTypeParameterIsResolvedToKeyOfAllBeings(boolean typeParameterIsResolvedToKeyOfAllBeings) {
this.typeParameterIsResolvedToItemB = typeParameterIsResolvedToItemB; this.typeParameterIsResolvedToKeyOfAllBeings = typeParameterIsResolvedToKeyOfAllBeings;
} }
} }

View File

@ -23,23 +23,22 @@ package org.mapstruct.ap.test.abstractclass.generics;
* *
*/ */
public class Target { public class Target {
private ItemC itemC; private AnimalKey animalKey;
private ItemB itemB; private KeyOfAllBeings keyOfAllBeings;
public ItemC getItemC() { public AnimalKey getAnimalKey() {
return itemC; return animalKey;
} }
public void setItemC(ItemC itemC) { public void setAnimalKey(AnimalKey animalKey) {
this.itemC = itemC; this.animalKey = animalKey;
} }
public ItemB getItemB() { public KeyOfAllBeings getKeyOfAllBeings() {
return itemB; return keyOfAllBeings;
} }
public void setItemB(ItemB itemB) { public void setKeyOfAllBeings(KeyOfAllBeings keyOfAllBeings) {
this.itemB = itemB; this.keyOfAllBeings = keyOfAllBeings;
} }
} }