Search in sources :

Example 46 with GenericClass

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

the class TestGenericClass method testIterableAndListBoundaries.

@SuppressWarnings("rawtypes")
@Test
public void testIterableAndListBoundaries() {
    Map<TypeVariable<?>, Type> typeMap = new HashMap<TypeVariable<?>, Type>();
    final GenericClass iterableIntegerClass = new GenericClass(new TypeToken<java.lang.Iterable<Integer>>() {
    }.getType());
    TypeVariable<?> var = new TypeVariable() {

        public AnnotatedType[] getAnnotatedBounds() {
            return null;
        }

        @Override
        public Type[] getBounds() {
            return new Type[] { iterableIntegerClass.getType() };
        }

        @Override
        public GenericDeclaration getGenericDeclaration() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getName() {
            return "Test";
        }

        /* (non-Javadoc)
			 * @see java.lang.Object#toString()
			 */
        @Override
        public String toString() {
            return "Dummy Variable";
        }

        public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
            // TODO Auto-generated method stub
            return null;
        }

        public Annotation[] getAnnotations() {
            // TODO Auto-generated method stub
            return null;
        }

        public Annotation[] getDeclaredAnnotations() {
            // TODO Auto-generated method stub
            return null;
        }
    };
    typeMap.put(var, iterableIntegerClass.getType());
    GenericClass arrayListClass = new GenericClass(new TypeToken<java.util.ArrayList<String>>() {
    }.getType());
    Assert.assertFalse(arrayListClass.satisfiesBoundaries(var, typeMap));
    arrayListClass = new GenericClass(new TypeToken<java.util.ArrayList<Integer>>() {
    }.getType());
    Assert.assertTrue(arrayListClass.satisfiesBoundaries(var, typeMap));
}
Also used : HashMap(java.util.HashMap) Annotation(java.lang.annotation.Annotation) WildcardType(java.lang.reflect.WildcardType) AnnotatedType(java.lang.reflect.AnnotatedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) AnnotatedType(java.lang.reflect.AnnotatedType) TypeVariable(java.lang.reflect.TypeVariable) GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) GenericClass(org.evosuite.utils.generic.GenericClass) Test(org.junit.Test)

Example 47 with GenericClass

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

the class TestGenericClass method testWildcardWithSuperIntegerBoundaryInstantiation.

@Test
public void testWildcardWithSuperIntegerBoundaryInstantiation() throws ConstructionFailedException {
    GenericClass integerWildcardListClass = new GenericClass(new TypeToken<java.util.List<? super Integer>>() {
    }.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.assertTrue(integerWildcardListClass.isAssignableFrom(integerListClass));
    Assert.assertTrue(integerWildcardListClass.isAssignableFrom(numberListClass));
    Assert.assertTrue(integerWildcardListClass.isAssignableFrom(objectListClass));
    GenericClass integerWildcardListInstantiation = integerWildcardListClass.getGenericInstantiation();
    Assert.assertTrue(integerWildcardListClass.isAssignableFrom(integerWildcardListInstantiation));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) Test(org.junit.Test)

Example 48 with GenericClass

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

the class TestGenericClass method testWildcardDateBothBoundaries2.

@Test
public void testWildcardDateBothBoundaries2() {
    WildcardType objectType = new WildcardTypeImpl(new Type[] { Comparable.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));
    // Does not satisfy lower boundary
    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 49 with GenericClass

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

the class TestGenericClass method testAssignableIntegerObject.

@Test
public void testAssignableIntegerObject() {
    GenericClass clazz1 = new GenericClass(Integer.class);
    GenericClass clazz2 = new GenericClass(Object.class);
    Assert.assertTrue(clazz1.isAssignableTo(clazz2));
    Assert.assertFalse(clazz1.isAssignableFrom(clazz2));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) Test(org.junit.Test)

Example 50 with GenericClass

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

the class MethodDescriptorTest method testMatcher.

@Test
public void testMatcher() throws Exception {
    Class<?> klass = Graphics2D.class;
    Method m = klass.getDeclaredMethod("getRenderingHint", RenderingHints.Key.class);
    MethodDescriptor md = new MethodDescriptor(m, new GenericClass(m.getReturnType()));
    String res = md.getInputParameterMatchers();
    assertTrue(res, res.contains("any("));
    assertTrue(res, res.contains("RenderingHints"));
    assertTrue(res, res.contains("Key"));
    assertFalse(res, res.contains("$"));
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) Method(java.lang.reflect.Method) 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