use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.
the class TestGenericClass method testWildcardInstantiation.
@Test
public void testWildcardInstantiation() throws ConstructionFailedException {
GenericClass integerWildcardListClass = new GenericClass(new TypeToken<java.util.List<? extends Integer>>() {
}.getType());
GenericClass integerListClass = new GenericClass(new TypeToken<java.util.List<Integer>>() {
}.getType());
GenericClass objectListClass = new GenericClass(new TypeToken<java.util.List<Object>>() {
}.getType());
Assert.assertTrue(integerWildcardListClass.isAssignableFrom(integerListClass));
Assert.assertFalse(integerWildcardListClass.isAssignableFrom(objectListClass));
GenericClass integerWildcardListInstantiation = integerWildcardListClass.getGenericInstantiation();
Assert.assertTrue(integerWildcardListClass.isAssignableFrom(integerWildcardListInstantiation));
}
use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.
the class TestGenericClass method testGenericSuperclassToWildcardList.
@Test
public void testGenericSuperclassToWildcardList() {
GenericClass listOfWildcard = new GenericClass(new TypeToken<List<Integer>>() {
}.getType()).getWithWildcardTypes();
GenericClass linkedlistOfInteger = new GenericClass(new TypeToken<LinkedList<Integer>>() {
}.getType());
Assert.assertTrue(linkedlistOfInteger.canBeInstantiatedTo(listOfWildcard));
Assert.assertFalse(listOfWildcard.canBeInstantiatedTo(linkedlistOfInteger));
}
use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.
the class TestGenericClass method testGenericSuperclassWildcards.
@Test
public void testGenericSuperclassWildcards() {
GenericClass listOfInteger = new GenericClass(new TypeToken<List<Integer>>() {
}.getType());
GenericClass listOfWildcard = new GenericClass(new TypeToken<List<?>>() {
}.getType());
Assert.assertTrue(listOfWildcard.isGenericSuperTypeOf(listOfInteger));
Assert.assertFalse(listOfInteger.isGenericSuperTypeOf(listOfWildcard));
Assert.assertTrue(listOfInteger.hasGenericSuperType(listOfWildcard));
Assert.assertFalse(listOfWildcard.hasGenericSuperType(listOfInteger));
GenericClass mapOfInteger = new GenericClass(new TypeToken<Map<Integer, String>>() {
}.getType());
GenericClass mapOfWildcard = new GenericClass(new TypeToken<Map<?, ?>>() {
}.getType());
Assert.assertTrue(mapOfWildcard.isGenericSuperTypeOf(mapOfInteger));
Assert.assertFalse(mapOfInteger.isGenericSuperTypeOf(mapOfWildcard));
Assert.assertTrue(mapOfInteger.hasGenericSuperType(mapOfWildcard));
Assert.assertFalse(mapOfWildcard.hasGenericSuperType(mapOfInteger));
}
use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.
the class TestGenericClass method testIterableAndList.
@Test
public void testIterableAndList() throws ConstructionFailedException {
GenericClass iterableIntegerClass = new GenericClass(new TypeToken<java.lang.Iterable<Integer>>() {
}.getType());
GenericClass arrayListClass = new GenericClass(java.util.ArrayList.class);
Assert.assertTrue(arrayListClass.canBeInstantiatedTo(iterableIntegerClass));
Assert.assertFalse(iterableIntegerClass.canBeInstantiatedTo(arrayListClass));
GenericClass instantiatedList = arrayListClass.getWithParametersFromSuperclass(iterableIntegerClass);
Type parameterType = instantiatedList.getParameterTypes().get(0);
Assert.assertEquals(Integer.class, GenericTypeReflector.erase(parameterType));
}
use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.
the class TestGenericClass method testGenericSuperclassFromWildcardList.
@Test
public void testGenericSuperclassFromWildcardList() {
GenericClass listOfInteger = new GenericClass(new TypeToken<List<Integer>>() {
}.getType());
GenericClass linkedlistOfWildcard = new GenericClass(new TypeToken<LinkedList<Integer>>() {
}.getType()).getWithWildcardTypes();
Assert.assertTrue(linkedlistOfWildcard.canBeInstantiatedTo(listOfInteger));
Assert.assertFalse(listOfInteger.canBeInstantiatedTo(linkedlistOfWildcard));
}
Aggregations