Search in sources :

Example 41 with GenericClass

use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.

the class TestGenericClass method testTypeVariableBoundariesComparable.

@Test
public void testTypeVariableBoundariesComparable() {
    TypeVariable<?> comparableTypeVariable = ComparableBoundary.class.getTypeParameters()[0];
    GenericClass listOfIntegerClass = new GenericClass(Integer.class);
    GenericClass listOfSerializableClass = new GenericClass(Serializable.class);
    Assert.assertTrue(listOfIntegerClass.satisfiesBoundaries(comparableTypeVariable));
    Assert.assertFalse(listOfSerializableClass.satisfiesBoundaries(comparableTypeVariable));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) Test(org.junit.Test)

Example 42 with GenericClass

use of org.evosuite.utils.generic.GenericClass 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 43 with GenericClass

use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.

the class TestGenericClass method testGuavaExample.

@Test
public void testGuavaExample() {
    Type abstractGuavaExampleString = new TypeToken<AbstractGuavaExample<String>>() {
    }.getType();
    Type guavaExample5 = new TypeToken<GuavaExample5<String>>() {
    }.getType();
    GenericClass abstractClass = new GenericClass(abstractGuavaExampleString);
    GenericClass concreteClass = new GenericClass(guavaExample5);
    Assert.assertTrue(TypeUtils.isAssignable(concreteClass.getType(), abstractClass.getType()));
    Assert.assertTrue("Cannot assign " + concreteClass + " to " + abstractClass, abstractClass.isAssignableFrom(concreteClass));
    Assert.assertTrue(concreteClass.isAssignableTo(abstractClass));
}
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) GuavaExample5(com.examples.with.different.packagename.generic.GuavaExample5) AbstractGuavaExample(com.examples.with.different.packagename.generic.AbstractGuavaExample) Test(org.junit.Test)

Example 44 with GenericClass

use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.

the class TestGenericClass method testWildcardClassloader.

@Test
public void testWildcardClassloader() {
    GenericClass clazz = new GenericClass(Class.class).getWithWildcardTypes();
    assertEquals("java.lang.Class<?>", clazz.getTypeName());
    clazz.changeClassLoader(TestGenericClass.class.getClassLoader());
    assertEquals("java.lang.Class<?>", clazz.getTypeName());
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) GenericClass(org.evosuite.utils.generic.GenericClass) Test(org.junit.Test)

Example 45 with GenericClass

use of org.evosuite.utils.generic.GenericClass 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

GenericClass (org.evosuite.utils.generic.GenericClass)144 Test (org.junit.Test)64 GenericMethod (org.evosuite.utils.generic.GenericMethod)40 Method (java.lang.reflect.Method)36 VariableReference (org.evosuite.testcase.variable.VariableReference)25 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)24 WildcardType (java.lang.reflect.WildcardType)22 TypeToken (com.googlecode.gentyref.TypeToken)20 ConstructionFailedException (org.evosuite.ga.ConstructionFailedException)17 Type (java.lang.reflect.Type)16 ArrayList (java.util.ArrayList)16 GenericAccessibleObject (org.evosuite.utils.generic.GenericAccessibleObject)16 MethodStatement (org.evosuite.testcase.statements.MethodStatement)15 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)15 ParameterizedType (java.lang.reflect.ParameterizedType)14 WildcardTypeImpl (org.evosuite.utils.generic.WildcardTypeImpl)10 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)9 AnnotatedType (java.lang.reflect.AnnotatedType)8 LinkedList (java.util.LinkedList)8 List (java.util.List)7