Search in sources :

Example 1 with TypeToken

use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.

the class TestGenericClass method testWildcardWithSuperNumberBoundaryInstantiation.

@Test
public void testWildcardWithSuperNumberBoundaryInstantiation() throws ConstructionFailedException {
    GenericClass numberWildcardListClass = new GenericClass(new TypeToken<java.util.List<? super Number>>() {
    }.getType());
    GenericClass integerListClass = new GenericClass(new TypeToken<java.util.List<Integer>>() {
    }.getType());
    GenericClass numberListClass = new GenericClass(new TypeToken<java.util.List<Number>>() {
    }.getType());
    GenericClass objectListClass = new GenericClass(new TypeToken<java.util.List<Object>>() {
    }.getType());
    Assert.assertFalse(numberWildcardListClass.isAssignableFrom(integerListClass));
    Assert.assertTrue(numberWildcardListClass.isAssignableFrom(numberListClass));
    Assert.assertTrue(numberWildcardListClass.isAssignableFrom(objectListClass));
    GenericClass integerWildcardListInstantiation = numberWildcardListClass.getGenericInstantiation();
    System.out.println(integerWildcardListInstantiation.toString());
    Assert.assertTrue(numberWildcardListClass.isAssignableFrom(integerWildcardListInstantiation));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) Test(org.junit.Test)

Example 2 with TypeToken

use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.

the class TestGenericClass method testGenericInstantiationIntegerList.

@SuppressWarnings("rawtypes")
@Test
public void testGenericInstantiationIntegerList() throws ConstructionFailedException {
    GenericClass listOfInteger = new GenericClass(new TypeToken<List<Integer>>() {
    }.getType());
    GenericClass linkedlistOfTypeVariable = new GenericClass(new TypeToken<LinkedList>() {
    }.getType());
    GenericClass instantiatedClass = linkedlistOfTypeVariable.getWithParametersFromSuperclass(listOfInteger);
    // GenericClass instantiatedClass = linkedlistOfTypeVariable.getGenericInstantiation(listOfInteger.getTypeVariableMap());
    Assert.assertEquals(Integer.class, instantiatedClass.getParameterTypes().get(0));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) Test(org.junit.Test)

Example 3 with TypeToken

use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.

the class TestGenericClass method testGenericSuperclassConcreteList.

@Test
public void testGenericSuperclassConcreteList() {
    GenericClass listOfInteger = new GenericClass(new TypeToken<List<Integer>>() {
    }.getType());
    GenericClass linkedlistOfInteger = new GenericClass(new TypeToken<LinkedList<Integer>>() {
    }.getType());
    Assert.assertTrue(linkedlistOfInteger.canBeInstantiatedTo(listOfInteger));
    Assert.assertFalse(listOfInteger.canBeInstantiatedTo(linkedlistOfInteger));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) Test(org.junit.Test)

Example 4 with TypeToken

use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.

the class TestGenericClass method testGenericInstantiationMapSubclass.

@SuppressWarnings("rawtypes")
@Test
public void testGenericInstantiationMapSubclass() throws ConstructionFailedException {
    GenericClass mapOfStringAndWildcard = new GenericClass(new TypeToken<Map<String, ?>>() {
    }.getType());
    GenericClass hashMapClass = new GenericClass(new TypeToken<HashMap>() {
    }.getType());
    GenericClass instantiatedClass = hashMapClass.getWithParametersFromSuperclass(mapOfStringAndWildcard);
    // GenericClass instantiatedClass = linkedlistOfTypeVariable.getGenericInstantiation(listOfInteger.getTypeVariableMap());
    System.out.println(instantiatedClass.toString());
    Assert.assertEquals(String.class, instantiatedClass.getParameterTypes().get(0));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) Test(org.junit.Test)

Example 5 with TypeToken

use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.

the class TestGenericClass method testGenericSuperclassToTypeVariableList.

@SuppressWarnings("rawtypes")
@Test
public void testGenericSuperclassToTypeVariableList() {
    GenericClass listOfTypeVariable = new GenericClass(new TypeToken<List>() {
    }.getType());
    GenericClass linkedlistOfInteger = new GenericClass(new TypeToken<LinkedList<Integer>>() {
    }.getType());
    Assert.assertTrue(linkedlistOfInteger.canBeInstantiatedTo(listOfTypeVariable));
    Assert.assertFalse(listOfTypeVariable.canBeInstantiatedTo(linkedlistOfInteger));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) 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