Search in sources :

Example 31 with GenericClass

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

the class TestGenericClass method test3.

@Test
public void test3() {
    Type listOfInteger = new TypeToken<List<Integer>>() {
    }.getType();
    Type listOfSerializable = new TypeToken<List<Serializable>>() {
    }.getType();
    GenericClass listOfIntegerClass = new GenericClass(listOfInteger);
    GenericClass listOfSerializableClass = new GenericClass(listOfSerializable);
    Assert.assertFalse(listOfIntegerClass.isAssignableFrom(listOfSerializableClass));
    Assert.assertFalse(listOfSerializableClass.isAssignableFrom(listOfIntegerClass));
    Assert.assertTrue(listOfIntegerClass.isAssignableFrom(listOfIntegerClass));
    Assert.assertTrue(listOfSerializableClass.isAssignableFrom(listOfSerializableClass));
}
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) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.Test)

Example 32 with GenericClass

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

the class TestGenericClass method testAssignableClass.

@Test
public void testAssignableClass() {
    GenericClass clazzTypeVar = new GenericClass(Class.class);
    GenericClass clazzWildcard = clazzTypeVar.getWithWildcardTypes();
    ParameterizedType type = new ParameterizedTypeImpl(Class.class, new Type[] { Integer.class }, null);
    GenericClass clazzConcrete = new GenericClass(type);
    Assert.assertFalse(clazzWildcard.isAssignableTo(clazzConcrete));
    Assert.assertFalse(clazzWildcard.isAssignableTo(clazzTypeVar));
    Assert.assertTrue(clazzWildcard.isAssignableTo(clazzWildcard));
    Assert.assertFalse(clazzTypeVar.isAssignableTo(clazzConcrete));
    Assert.assertTrue(clazzTypeVar.isAssignableTo(clazzTypeVar));
    Assert.assertTrue(clazzTypeVar.isAssignableTo(clazzWildcard));
    Assert.assertTrue(clazzConcrete.isAssignableTo(clazzConcrete));
    Assert.assertFalse(clazzConcrete.isAssignableTo(clazzTypeVar));
    Assert.assertTrue(clazzConcrete.isAssignableTo(clazzWildcard));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) GenericClass(org.evosuite.utils.generic.GenericClass) Test(org.junit.Test)

Example 33 with GenericClass

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

the class TestGenericClass method testPrimitiveWrapper.

@Test
public void testPrimitiveWrapper() {
    GenericClass integerClass = new GenericClass(Integer.class);
    GenericClass intClass = new GenericClass(int.class);
    Assert.assertTrue(integerClass.canBeInstantiatedTo(intClass));
    Assert.assertFalse(intClass.canBeInstantiatedTo(integerClass));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) Test(org.junit.Test)

Example 34 with GenericClass

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

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

the class TestGenericClass method test1.

@Test
public void test1() {
    Type listOfString = new TypeToken<List<String>>() {
    }.getType();
    Type listOfInteger = new TypeToken<List<Integer>>() {
    }.getType();
    GenericClass listOfStringClass = new GenericClass(listOfString);
    GenericClass listOfIntegerClass = new GenericClass(listOfInteger);
    Assert.assertFalse(listOfStringClass.isAssignableFrom(listOfIntegerClass));
    Assert.assertFalse(listOfStringClass.isAssignableTo(listOfIntegerClass));
}
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) LinkedList(java.util.LinkedList) List(java.util.List) 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