Search in sources :

Example 16 with TypeToken

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));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) Test(org.junit.Test)

Example 17 with TypeToken

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));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.Test)

Example 18 with TypeToken

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));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) Test(org.junit.Test)

Example 19 with TypeToken

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));
}
Also used : WildcardType(java.lang.reflect.WildcardType) AnnotatedType(java.lang.reflect.AnnotatedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) Test(org.junit.Test)

Example 20 with TypeToken

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));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

TypeToken (com.googlecode.gentyref.TypeToken)20 GenericClass (org.evosuite.utils.generic.GenericClass)20 Test (org.junit.Test)20 Method (java.lang.reflect.Method)6 GenericMethod (org.evosuite.utils.generic.GenericMethod)6 ParameterizedType (java.lang.reflect.ParameterizedType)3 AnnotatedType (java.lang.reflect.AnnotatedType)2 Type (java.lang.reflect.Type)2 WildcardType (java.lang.reflect.WildcardType)2 LinkedList (java.util.LinkedList)2 GuavaExample4 (com.examples.with.different.packagename.generic.GuavaExample4)1 Annotation (java.lang.annotation.Annotation)1 TypeVariable (java.lang.reflect.TypeVariable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Assertion (org.evosuite.assertion.Assertion)1 Inspector (org.evosuite.assertion.Inspector)1 InspectorAssertion (org.evosuite.assertion.InspectorAssertion)1 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)1