mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#693 Renaming test entities in generics test for the sake of easier understanding
This commit is contained in:
parent
55b74ae384
commit
c59ef3ab7a
@ -21,7 +21,7 @@ package org.mapstruct.ap.test.abstractclass.generics;
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
public abstract class AbstractClassExposingItemC
|
||||
implements ItemProviderSomeItemA<ItemB>, ItemProviderSomeItemB<ItemC> {
|
||||
public abstract class AbstractAnimal
|
||||
implements Identifiable<KeyOfAllBeings>, IAnimal<AnimalKey> {
|
||||
|
||||
}
|
@ -18,6 +18,6 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.abstractclass.generics;
|
||||
|
||||
public abstract class AbstractClassExposingItemB
|
||||
implements ItemProviderAny<ItemB>, ItemProviderSomeItemA<ItemA> {
|
||||
public abstract class AbstractHuman
|
||||
implements GenericIdentifiable<KeyOfAllBeings>, Identifiable<Key> {
|
||||
}
|
@ -22,14 +22,14 @@ package org.mapstruct.ap.test.abstractclass.generics;
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
public class ItemC extends ItemB {
|
||||
private boolean typeParameterIsResolvedToItemC;
|
||||
public class AnimalKey extends KeyOfAllBeings {
|
||||
private boolean typeParameterIsResolvedToAnimalKey;
|
||||
|
||||
public boolean typeParameterIsResolvedToItemC() {
|
||||
return typeParameterIsResolvedToItemC;
|
||||
public boolean typeParameterIsResolvedToAnimalKey() {
|
||||
return typeParameterIsResolvedToAnimalKey;
|
||||
}
|
||||
|
||||
public void setTypeParameterIsResolvedToItemC(boolean typeParameterIsResolvedToItemC) {
|
||||
this.typeParameterIsResolvedToItemC = typeParameterIsResolvedToItemC;
|
||||
public void setTypeParameterIsResolvedToAnimalKey(boolean typeParameterIsResolvedToAnimalKey) {
|
||||
this.typeParameterIsResolvedToAnimalKey = typeParameterIsResolvedToAnimalKey;
|
||||
}
|
||||
}
|
@ -22,14 +22,14 @@ package org.mapstruct.ap.test.abstractclass.generics;
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
public class SourceWithItemB extends AbstractClassExposingItemB {
|
||||
private ItemB item;
|
||||
public class Child extends AbstractHuman {
|
||||
private KeyOfAllBeings key;
|
||||
|
||||
public ItemB getItem() {
|
||||
return item;
|
||||
public KeyOfAllBeings getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setItem(ItemB item) {
|
||||
this.item = item;
|
||||
public void setKey(KeyOfAllBeings key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
@ -22,16 +22,16 @@ package org.mapstruct.ap.test.abstractclass.generics;
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
public class SourceWithItemC extends AbstractClassExposingItemC {
|
||||
private ItemC item;
|
||||
public class Elephant extends AbstractAnimal {
|
||||
private AnimalKey key;
|
||||
|
||||
@Override
|
||||
public ItemC getItem() {
|
||||
return item;
|
||||
public AnimalKey getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(ItemC item) {
|
||||
this.item = item;
|
||||
public void setKey(AnimalKey key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
@ -21,8 +21,8 @@ package org.mapstruct.ap.test.abstractclass.generics;
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
public interface ItemProviderAny<X> {
|
||||
X getItem();
|
||||
public interface GenericIdentifiable<X> {
|
||||
X getKey();
|
||||
|
||||
void setItem(X id);
|
||||
void setKey(X id);
|
||||
}
|
@ -32,25 +32,25 @@ import org.mapstruct.factory.Mappers;
|
||||
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 = "animalKey", source = "key")
|
||||
public abstract Target toTarget(AbstractAnimal source);
|
||||
|
||||
@Mapping(target = "itemB", source = "item")
|
||||
public abstract Target toTarget(AbstractClassExposingItemB source);
|
||||
@Mapping(target = "keyOfAllBeings", source = "key")
|
||||
public abstract Target toTarget(AbstractHuman source);
|
||||
|
||||
@Mapping(target = "item", source = "itemC")
|
||||
public abstract void intoSourceWithItemC(Target target, @MappingTarget AbstractClassExposingItemC bean);
|
||||
@Mapping(target = "key", source = "animalKey")
|
||||
public abstract void updateSourceWithAnimalKey(Target target, @MappingTarget AbstractAnimal bean);
|
||||
|
||||
@Mapping(target = "item", source = "itemB")
|
||||
public abstract void intoSourceWithItemB(Target target, @MappingTarget AbstractClassExposingItemB bean);
|
||||
@Mapping(target = "key", source = "keyOfAllBeings")
|
||||
public abstract void updateSourceWithKeyOfAllBeings(Target target, @MappingTarget AbstractHuman bean);
|
||||
|
||||
protected ItemC modifyItemC(ItemC item) {
|
||||
item.setTypeParameterIsResolvedToItemC( true );
|
||||
protected AnimalKey modifyAnimalKey(AnimalKey item) {
|
||||
item.setTypeParameterIsResolvedToAnimalKey( true );
|
||||
return item;
|
||||
}
|
||||
|
||||
protected ItemB modifyItemB(ItemB item) {
|
||||
item.setTypeParameterIsResolvedToItemB( true );
|
||||
protected KeyOfAllBeings modifyKeyOfAllBeings(KeyOfAllBeings item) {
|
||||
item.setTypeParameterIsResolvedToKeyOfAllBeings( true );
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
@ -33,67 +33,67 @@ import static org.fest.assertions.Assertions.assertThat;
|
||||
@RunWith(AnnotationProcessorTestRunner.class)
|
||||
@IssueKey("644,687,688")
|
||||
@WithClasses({
|
||||
AbstractClassExposingItemC.class,
|
||||
AbstractClassExposingItemB.class,
|
||||
AbstractAnimal.class,
|
||||
AbstractHuman.class,
|
||||
GenericsHierarchyMapper.class,
|
||||
ItemA.class,
|
||||
ItemB.class,
|
||||
ItemC.class,
|
||||
ItemProviderSomeItemA.class,
|
||||
ItemProviderAny.class,
|
||||
ItemProviderSomeItemB.class,
|
||||
Key.class,
|
||||
KeyOfAllBeings.class,
|
||||
AnimalKey.class,
|
||||
Identifiable.class,
|
||||
GenericIdentifiable.class,
|
||||
IAnimal.class,
|
||||
Target.class
|
||||
})
|
||||
public class GenericsHierarchyTest {
|
||||
|
||||
@Test
|
||||
public void determinesItemCSourceGetter() {
|
||||
AbstractClassExposingItemC source = new SourceWithItemC();
|
||||
public void determinesAnimalKeyGetter() {
|
||||
AbstractAnimal source = new Elephant();
|
||||
|
||||
source.setItem( new ItemC() );
|
||||
source.setKey( new AnimalKey() );
|
||||
// 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 );
|
||||
|
||||
assertThat( target.getItemC().typeParameterIsResolvedToItemC() ).isTrue();
|
||||
assertThat( target.getItemC().typeParameterIsResolvedToItemB() ).isFalse();
|
||||
assertThat( target.getAnimalKey().typeParameterIsResolvedToAnimalKey() ).isTrue();
|
||||
assertThat( target.getAnimalKey().typeParameterIsResolvedToKeyOfAllBeings() ).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determinesItemBSourceGetter() {
|
||||
AbstractClassExposingItemB source = new SourceWithItemB();
|
||||
public void determinesKeyOfAllBeingsGetter() {
|
||||
AbstractHuman source = new Child();
|
||||
|
||||
source.setItem( new ItemB() );
|
||||
source.setKey( new KeyOfAllBeings() );
|
||||
// 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 );
|
||||
|
||||
assertThat( target.getItemB().typeParameterIsResolvedToItemB() ).isTrue();
|
||||
assertThat( target.getKeyOfAllBeings().typeParameterIsResolvedToKeyOfAllBeings() ).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determinesItemCSourceSetter() {
|
||||
Target target = new Target();
|
||||
|
||||
target.setItemC( new ItemC() );
|
||||
target.setAnimalKey( new AnimalKey() );
|
||||
|
||||
SourceWithItemC source = new SourceWithItemC();
|
||||
GenericsHierarchyMapper.INSTANCE.intoSourceWithItemC( target, source );
|
||||
Elephant source = new Elephant();
|
||||
GenericsHierarchyMapper.INSTANCE.updateSourceWithAnimalKey( target, source );
|
||||
|
||||
assertThat( source.getItem().typeParameterIsResolvedToItemC() ).isTrue();
|
||||
assertThat( source.getKey().typeParameterIsResolvedToAnimalKey() ).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determinesItemBSourceSetter() {
|
||||
Target target = new Target();
|
||||
|
||||
target.setItemB( new ItemB() );
|
||||
target.setKeyOfAllBeings( new KeyOfAllBeings() );
|
||||
|
||||
SourceWithItemB source = new SourceWithItemB();
|
||||
GenericsHierarchyMapper.INSTANCE.intoSourceWithItemB( target, source );
|
||||
Child source = new Child();
|
||||
GenericsHierarchyMapper.INSTANCE.updateSourceWithKeyOfAllBeings( target, source );
|
||||
|
||||
assertThat( source.getItem().typeParameterIsResolvedToItemB() ).isTrue();
|
||||
assertThat( source.getKey().typeParameterIsResolvedToKeyOfAllBeings() ).isTrue();
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ package org.mapstruct.ap.test.abstractclass.generics;
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
public interface ItemProviderSomeItemB<ID extends ItemB> extends ItemProviderSomeItemA<ItemB> {
|
||||
public interface IAnimal<ID extends KeyOfAllBeings> extends Identifiable<KeyOfAllBeings> {
|
||||
@Override
|
||||
ID getItem();
|
||||
ID getKey();
|
||||
|
||||
void setItem(ID item);
|
||||
void setKey(ID item);
|
||||
}
|
@ -21,6 +21,6 @@ package org.mapstruct.ap.test.abstractclass.generics;
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
public interface ItemProviderSomeItemA<T extends ItemA> {
|
||||
T getItem();
|
||||
public interface Identifiable<T extends Key> {
|
||||
T getKey();
|
||||
}
|
@ -22,6 +22,6 @@ package org.mapstruct.ap.test.abstractclass.generics;
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
public class ItemA {
|
||||
public class Key {
|
||||
|
||||
}
|
@ -22,14 +22,14 @@ package org.mapstruct.ap.test.abstractclass.generics;
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
public class ItemB extends ItemA {
|
||||
private boolean typeParameterIsResolvedToItemB;
|
||||
public class KeyOfAllBeings extends Key {
|
||||
private boolean typeParameterIsResolvedToKeyOfAllBeings;
|
||||
|
||||
public boolean typeParameterIsResolvedToItemB() {
|
||||
return typeParameterIsResolvedToItemB;
|
||||
public boolean typeParameterIsResolvedToKeyOfAllBeings() {
|
||||
return typeParameterIsResolvedToKeyOfAllBeings;
|
||||
}
|
||||
|
||||
public void setTypeParameterIsResolvedToItemB(boolean typeParameterIsResolvedToItemB) {
|
||||
this.typeParameterIsResolvedToItemB = typeParameterIsResolvedToItemB;
|
||||
public void setTypeParameterIsResolvedToKeyOfAllBeings(boolean typeParameterIsResolvedToKeyOfAllBeings) {
|
||||
this.typeParameterIsResolvedToKeyOfAllBeings = typeParameterIsResolvedToKeyOfAllBeings;
|
||||
}
|
||||
}
|
@ -23,23 +23,22 @@ package org.mapstruct.ap.test.abstractclass.generics;
|
||||
*
|
||||
*/
|
||||
public class Target {
|
||||
private ItemC itemC;
|
||||
private ItemB itemB;
|
||||
private AnimalKey animalKey;
|
||||
private KeyOfAllBeings keyOfAllBeings;
|
||||
|
||||
public ItemC getItemC() {
|
||||
return itemC;
|
||||
public AnimalKey getAnimalKey() {
|
||||
return animalKey;
|
||||
}
|
||||
|
||||
public void setItemC(ItemC itemC) {
|
||||
this.itemC = itemC;
|
||||
public void setAnimalKey(AnimalKey animalKey) {
|
||||
this.animalKey = animalKey;
|
||||
}
|
||||
|
||||
public ItemB getItemB() {
|
||||
return itemB;
|
||||
public KeyOfAllBeings getKeyOfAllBeings() {
|
||||
return keyOfAllBeings;
|
||||
}
|
||||
|
||||
public void setItemB(ItemB itemB) {
|
||||
this.itemB = itemB;
|
||||
public void setKeyOfAllBeings(KeyOfAllBeings keyOfAllBeings) {
|
||||
this.keyOfAllBeings = keyOfAllBeings;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user