use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.
the class TestGenericAccessibleObject method testGenericMethodFromReturnValueWithSubclass.
@Test
public void testGenericMethodFromReturnValueWithSubclass() throws SecurityException, NoSuchMethodException, ConstructionFailedException {
Class<?> targetClass = com.examples.with.different.packagename.generic.GenericClassWithGenericMethodAndSubclass.class;
Method targetMethod = targetClass.getMethod("wrap", new Class<?>[] { Object.class });
GenericMethod genericMethod = new GenericMethod(targetMethod, targetClass);
GenericClass generatedType = new GenericClass(new TypeToken<com.examples.with.different.packagename.generic.GenericClassWithGenericMethodAndSubclass.Foo<String>>() {
}.getType());
GenericMethod instantiatedMethod = genericMethod.getGenericInstantiationFromReturnValue(generatedType);
Assert.assertEquals(instantiatedMethod.getGeneratedClass().getParameterTypes().get(0), String.class);
}
use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.
the class TestGenericAccessibleObject method testGenericMethodFromReturnValue.
@Test
public void testGenericMethodFromReturnValue() throws SecurityException, NoSuchMethodException, ConstructionFailedException {
Class<?> targetClass = com.examples.with.different.packagename.generic.GenericMethodWithBounds.class;
Method targetMethod = targetClass.getMethod("is", new Class<?>[] { Comparable.class });
GenericMethod genericMethod = new GenericMethod(targetMethod, targetClass);
GenericClass generatedType = new GenericClass(new TypeToken<java.util.List<Integer>>() {
}.getType());
GenericMethod instantiatedMethod = genericMethod.getGenericInstantiationFromReturnValue(generatedType);
Assert.assertEquals(instantiatedMethod.getGeneratedClass(), generatedType);
}
use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.
the class TestGenericAccessibleObject method testGenericMethodAbstractType.
@Test
public void testGenericMethodAbstractType() throws SecurityException, NoSuchMethodException, ConstructionFailedException {
Class<?> targetClass = com.examples.with.different.packagename.generic.ConcreteGenericClass.class;
Method targetMethod = targetClass.getMethod("create", new Class<?>[] { int.class });
GenericMethod genericMethod = new GenericMethod(targetMethod, targetClass);
Assert.assertEquals(genericMethod.getGeneratedClass().getRawClass(), com.examples.with.different.packagename.generic.ConcreteGenericClass.class);
GenericClass iterableIntegerClass = new GenericClass(new TypeToken<com.examples.with.different.packagename.generic.AbstractGenericClass<java.lang.Integer>>() {
}.getType());
GenericMethod instantiatedMethod = genericMethod.getGenericInstantiationFromReturnValue(iterableIntegerClass);
System.out.println(instantiatedMethod.getGeneratedClass().toString());
Assert.assertEquals(instantiatedMethod.getGeneratedClass().getRawClass(), com.examples.with.different.packagename.generic.ConcreteGenericClass.class);
instantiatedMethod = genericMethod.copyWithOwnerFromReturnType(iterableIntegerClass);
System.out.println(instantiatedMethod.getGeneratedClass().toString());
Assert.assertEquals(instantiatedMethod.getGeneratedClass().getRawClass(), com.examples.with.different.packagename.generic.ConcreteGenericClass.class);
instantiatedMethod = genericMethod.getGenericInstantiation(iterableIntegerClass);
System.out.println(instantiatedMethod.getGeneratedClass().toString());
Assert.assertEquals(instantiatedMethod.getGeneratedClass().getRawClass(), com.examples.with.different.packagename.generic.ConcreteGenericClass.class);
instantiatedMethod = genericMethod.copyWithNewOwner(iterableIntegerClass);
System.out.println(instantiatedMethod.getGeneratedClass().toString());
Assert.assertEquals(instantiatedMethod.getGeneratedClass().getRawClass(), com.examples.with.different.packagename.generic.ConcreteGenericClass.class);
}
use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.
the class TestGenericClass method testGenericSuperclassFromTypeVariableList.
@SuppressWarnings("rawtypes")
@Test
public void testGenericSuperclassFromTypeVariableList() {
GenericClass listOfInteger = new GenericClass(new TypeToken<List<Integer>>() {
}.getType());
GenericClass linkedlistOfTypeVariable = new GenericClass(new TypeToken<LinkedList>() {
}.getType());
Assert.assertTrue(linkedlistOfTypeVariable.canBeInstantiatedTo(listOfInteger));
Assert.assertFalse(listOfInteger.canBeInstantiatedTo(linkedlistOfTypeVariable));
}
use of com.googlecode.gentyref.TypeToken in project evosuite by EvoSuite.
the class TestGenericClass method testSatisfiesTypeVariableInSubtype.
@Test
public void testSatisfiesTypeVariableInSubtype() {
GenericClass iterableIntegerClass = new GenericClass(new TypeToken<com.examples.with.different.packagename.generic.GuavaExample4<java.lang.Iterable<Integer>>>() {
}.getType());
ParameterizedType iterableInteger = (ParameterizedType) iterableIntegerClass.getParameterTypes().get(0);
TypeVariable<?> typeVariable = ((Class<?>) iterableInteger.getRawType()).getTypeParameters()[0];
TypeVariable<?> iterableTypeVariable = iterableIntegerClass.getTypeVariables().get(0);
GenericClass listOfIntegerClass = new GenericClass(com.examples.with.different.packagename.generic.GuavaExample4.class);
// Object bound
Assert.assertTrue(iterableIntegerClass.satisfiesBoundaries(typeVariable));
Assert.assertTrue(listOfIntegerClass.satisfiesBoundaries(typeVariable));
// Iterable bound
Assert.assertTrue(iterableIntegerClass.satisfiesBoundaries(iterableTypeVariable));
Assert.assertTrue(listOfIntegerClass.satisfiesBoundaries(iterableTypeVariable));
}
Aggregations