Search in sources :

Example 36 with GenericClass

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

the class TestGenericClass method testWildcardDateSuperBoundaries.

@Test
public void testWildcardDateSuperBoundaries() {
    WildcardType objectType = new WildcardTypeImpl(new Type[] { Object.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.assertTrue(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 37 with GenericClass

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

the class TestGenericClass method test01.

@SuppressWarnings({ "rawtypes", "unused", "unchecked" })
@Test
public void test01() throws Throwable {
    /*
		 * This test case come from compilation issue found during SBST'13 competition:
		 * 
		 * String string0 = vM0.run(vM0.stack);
		 * 
		 * SUT at:  http://www.massapi.com/source/jabref-2.6/src/java/net/sf/jabref/bst/VM.java.html
		 * 
		 * Snippet of interest:
		 * 
		 * 1) Stack<Object> stack = new Stack<Object>();
		 * 2)  public String run(Collection<BibtexEntry> bibtex) {
		 */
    Collection<?> col0 = new Stack<Object>();
    Collection<A> col1 = new Stack();
    Collection col2 = new Stack();
    Collection col3 = new Stack<Object>();
    /*
		 *  following does not compile
		 *  
		 *  Collection<A> col = new Stack<Object>();
		 *  
		 *  but it can be generated by EvoSuite
		 */
    GenericClass stack = new GenericClass(Stack.class).getWithWildcardTypes();
    GenericClass collection = new GenericClass(Collection.class).getWithWildcardTypes();
    Assert.assertTrue(stack.isAssignableTo(collection));
    GenericClass objectStack = new GenericClass(col0.getClass());
    Assert.assertTrue(objectStack.isAssignableTo(collection));
    Type typeColA = new TypeToken<Collection<A>>() {
    }.getType();
    Type typeStack = new TypeToken<Stack>() {
    }.getType();
    Type typeObjectStack = new TypeToken<Stack<Object>>() {
    }.getType();
    GenericClass classColA = new GenericClass(typeColA);
    GenericClass classStack = new GenericClass(typeStack).getWithWildcardTypes();
    GenericClass classObjectStack = new GenericClass(typeObjectStack);
    Assert.assertFalse(classStack.isAssignableTo(classColA));
    Assert.assertFalse(classObjectStack.isAssignableTo(classColA));
    Assert.assertFalse(classColA.isAssignableFrom(classObjectStack));
}
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) Collection(java.util.Collection) Stack(java.util.Stack) Test(org.junit.Test)

Example 38 with GenericClass

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

the class TestGenericClass method testWildcardComparableBoundaries.

@Test
public void testWildcardComparableBoundaries() {
    WildcardType objectType = new WildcardTypeImpl(new Type[] { Comparable.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.assertTrue(comparableClass.satisfiesBoundaries(objectType));
    Assert.assertTrue(dateClass.satisfiesBoundaries(objectType));
    Assert.assertTrue(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 39 with GenericClass

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

the class TestGenericClass method test2.

@SuppressWarnings("rawtypes")
@Test
public void test2() {
    Type listOfString = new TypeToken<List<String>>() {
    }.getType();
    Type plainList = new TypeToken<List>() {
    }.getType();
    Type objectList = new TypeToken<List<Object>>() {
    }.getType();
    GenericClass listOfStringClass = new GenericClass(listOfString);
    GenericClass plainListClass = new GenericClass(plainList).getWithWildcardTypes();
    GenericClass objectListClass = new GenericClass(objectList);
    /*
		 * Note:
		 * 
		 * 		List<String> l = new LinkedList<Object>();
		 * 
		 *  does not compile
		 */
    Assert.assertFalse(listOfStringClass.isAssignableTo(objectListClass));
    Assert.assertFalse(listOfStringClass.isAssignableFrom(plainListClass));
    Assert.assertTrue(listOfStringClass.isAssignableTo(plainListClass));
}
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 40 with GenericClass

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

the class TestGenericClass method testAssignableObject.

@Test
public void testAssignableObject() {
    GenericClass clazz1 = new GenericClass(Object.class);
    GenericClass clazz2 = new GenericClass(Object.class);
    Assert.assertTrue(clazz1.isAssignableTo(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