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));
}
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());
}
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);
}
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));
}
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));
}
Aggregations