Search in sources :

Example 6 with WildcardTypeImpl

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

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

the class TestCodeVisitorTest method testGenerics_staticMethod.

@Test
public void testGenerics_staticMethod() throws NoSuchMethodException, ConstructionFailedException {
    // first construct a test case for the Generic method
    TestCase tc = new DefaultTestCase();
    TestFactory.getInstance().addConstructor(tc, new GenericConstructor(Object.class.getDeclaredConstructor(), Object.class), 0, 0);
    Method m = TestCodeVisitorTest.class.getDeclaredMethod("bar", Object.class);
    GenericMethod gm = new GenericMethod(m, TestCodeVisitorTest.class);
    TestFactory.getInstance().addMethod(tc, gm, 1, 0);
    // Check if generic types were correctly analyzed/inferred
    Type[] types = gm.getParameterTypes();
    // only 1 input
    assertEquals(1, types.length);
    Type type = types[0];
    Assert.assertNotNull(type);
    WildcardTypeImpl wt = (WildcardTypeImpl) type;
    assertEquals(0, wt.getLowerBounds().length);
    assertEquals(1, wt.getUpperBounds().length);
    Class<?> upper = (Class<?>) wt.getUpperBounds()[0];
    assertEquals(Object.class, upper);
    // Finally, visit the test
    TestCodeVisitor visitor = new TestCodeVisitor();
    // should not throw exception
    tc.accept(visitor);
    System.out.println(visitor.getCode());
}
Also used : Type(java.lang.reflect.Type) WildcardTypeImpl(org.evosuite.utils.generic.WildcardTypeImpl) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) EnumInInnerClass(com.examples.with.different.packagename.EnumInInnerClass) AbstractEnumInInnerClass(com.examples.with.different.packagename.AbstractEnumInInnerClass) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod) Test(org.junit.Test)

Example 8 with WildcardTypeImpl

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

the class TestCodeVisitorTest method testGenerics_staticMethodWithExtends.

@Test
public void testGenerics_staticMethodWithExtends() throws NoSuchMethodException, ConstructionFailedException {
    // first construct a test case for the Generic method
    TestCase tc = new DefaultTestCase();
    TestFactory.getInstance().addConstructor(tc, new GenericConstructor(FakeServlet.class.getDeclaredConstructor(), FakeServlet.class), 0, 0);
    Method m = TestCodeVisitorTest.class.getDeclaredMethod("foo", Servlet.class);
    GenericMethod gm = new GenericMethod(m, TestCodeVisitorTest.class);
    TestFactory.getInstance().addMethod(tc, gm, 1, 0);
    // Check if generic types were correctly analyzed/inferred
    Type[] types = gm.getParameterTypes();
    // only 1 input
    assertEquals(1, types.length);
    Type type = types[0];
    Assert.assertNotNull(type);
    WildcardTypeImpl wt = (WildcardTypeImpl) type;
    assertEquals(0, wt.getLowerBounds().length);
    assertEquals(1, wt.getUpperBounds().length);
    Class<?> upper = (Class<?>) wt.getUpperBounds()[0];
    assertEquals(Object.class, upper);
    // Finally, visit the test
    TestCodeVisitor visitor = new TestCodeVisitor();
    // should not throw exception
    tc.accept(visitor);
}
Also used : Type(java.lang.reflect.Type) WildcardTypeImpl(org.evosuite.utils.generic.WildcardTypeImpl) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) EnumInInnerClass(com.examples.with.different.packagename.EnumInInnerClass) AbstractEnumInInnerClass(com.examples.with.different.packagename.AbstractEnumInInnerClass) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod) Test(org.junit.Test)

Example 9 with WildcardTypeImpl

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

the class TestGenericClass method testWildcardDateBoundaries.

@Test
public void testWildcardDateBoundaries() {
    WildcardType objectType = new WildcardTypeImpl(new Type[] { java.util.Date.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.assertFalse(integerClass.satisfiesBoundaries(objectType));
    Assert.assertFalse(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 10 with WildcardTypeImpl

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

the class TestGenericClass method testWildcardDateBothBoundaries.

@Test
public void testWildcardDateBothBoundaries() {
    WildcardType objectType = new WildcardTypeImpl(new Type[] { java.util.Date.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 bound, so needs to be false
    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)

Aggregations

WildcardTypeImpl (org.evosuite.utils.generic.WildcardTypeImpl)12 Test (org.junit.Test)12 WildcardType (java.lang.reflect.WildcardType)10 GenericClass (org.evosuite.utils.generic.GenericClass)10 AbstractEnumInInnerClass (com.examples.with.different.packagename.AbstractEnumInInnerClass)2 EnumInInnerClass (com.examples.with.different.packagename.EnumInInnerClass)2 Method (java.lang.reflect.Method)2 Type (java.lang.reflect.Type)2 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)2 GenericMethod (org.evosuite.utils.generic.GenericMethod)2