Search in sources :

Example 26 with GenericClass

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

the class TestGenericClass method testWildcardNumberBoundaries.

@Test
public void testWildcardNumberBoundaries() {
    WildcardType objectType = new WildcardTypeImpl(new Type[] { Number.class }, new Type[] {});
    GenericClass integerClass = new GenericClass(Integer.class);
    GenericClass comparableClass = new GenericClass(Comparable.class);
    GenericClass dateClass = new GenericClass(java.util.Date.class);
    GenericClass sqlDateClass = new GenericClass(java.sql.Date.class);
    Assert.assertTrue(integerClass.satisfiesBoundaries(objectType));
    Assert.assertFalse(comparableClass.satisfiesBoundaries(objectType));
    Assert.assertFalse(dateClass.satisfiesBoundaries(objectType));
    Assert.assertFalse(sqlDateClass.satisfiesBoundaries(objectType));
}
Also used : WildcardType(java.lang.reflect.WildcardType) WildcardTypeImpl(org.evosuite.utils.generic.WildcardTypeImpl) GenericClass(org.evosuite.utils.generic.GenericClass) Test(org.junit.Test)

Example 27 with GenericClass

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

the class TestGenericClass method testWildcardInvalidBoundaries.

@Test
public void testWildcardInvalidBoundaries() {
    WildcardType objectType = new WildcardTypeImpl(new Type[] { Number.class }, new Type[] { java.util.Date.class });
    GenericClass integerClass = new GenericClass(Integer.class);
    GenericClass comparableClass = new GenericClass(Comparable.class);
    GenericClass dateClass = new GenericClass(java.util.Date.class);
    GenericClass sqlDateClass = new GenericClass(java.sql.Date.class);
    Assert.assertFalse(integerClass.satisfiesBoundaries(objectType));
    Assert.assertFalse(comparableClass.satisfiesBoundaries(objectType));
    Assert.assertFalse(dateClass.satisfiesBoundaries(objectType));
    Assert.assertFalse(sqlDateClass.satisfiesBoundaries(objectType));
}
Also used : WildcardType(java.lang.reflect.WildcardType) WildcardTypeImpl(org.evosuite.utils.generic.WildcardTypeImpl) GenericClass(org.evosuite.utils.generic.GenericClass) Test(org.junit.Test)

Example 28 with GenericClass

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

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

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

the class TestGenericClass method testAssignableIntInteger.

@Test
public void testAssignableIntInteger() {
    GenericClass clazz1 = new GenericClass(Integer.class);
    GenericClass clazz2 = new GenericClass(int.class);
    Assert.assertTrue(clazz1.isAssignableTo(clazz2));
    Assert.assertTrue(clazz1.isAssignableFrom(clazz2));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) 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