use of org.evosuite.utils.generic.GenericMethod 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 org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class TestGenericAccessibleObject method testGenericMethod.
@Test
public void testGenericMethod() throws SecurityException, NoSuchMethodException, ConstructionFailedException {
Class<?> targetClass = com.examples.with.different.packagename.generic.GenericMethod.class;
Method targetMethod = targetClass.getMethod("coverMe", new Class<?>[] { Object.class });
GenericMethod genericMethod = new GenericMethod(targetMethod, targetClass);
Assert.assertFalse(genericMethod.getOwnerClass().hasTypeVariables());
List<GenericClass> parameters = genericMethod.getParameterClasses();
Assert.assertFalse(parameters.get(0).hasTypeVariables());
Assert.assertTrue(parameters.get(0).hasWildcardTypes());
GenericMethod instantiatedMethod = genericMethod.getGenericInstantiation();
parameters = instantiatedMethod.getParameterClasses();
Assert.assertFalse(parameters.get(0).hasTypeVariables());
Assert.assertFalse(parameters.get(0).hasWildcardTypes());
}
use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class TestGenericAccessibleObject method testGenericMethodWithBounds.
@Test
public void testGenericMethodWithBounds() 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);
Assert.assertFalse(genericMethod.getOwnerClass().hasTypeVariables());
List<GenericClass> parameters = genericMethod.getParameterClasses();
Assert.assertFalse(parameters.get(0).hasTypeVariables());
Assert.assertTrue(parameters.get(0).hasWildcardTypes());
Assert.assertTrue(genericMethod.getGeneratedClass().hasWildcardTypes());
GenericMethod instantiatedMethod = genericMethod.getGenericInstantiation();
parameters = instantiatedMethod.getParameterClasses();
Assert.assertFalse(parameters.get(0).hasTypeVariables());
Assert.assertFalse(parameters.get(0).hasWildcardTypes());
Assert.assertFalse(instantiatedMethod.getGeneratedClass().hasWildcardTypes());
}
use of org.evosuite.utils.generic.GenericMethod 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 org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.
the class TestGenericAccessibleObject method testGenericMethodFromReturnValueTypeVariable.
@Test
public void testGenericMethodFromReturnValueTypeVariable() throws SecurityException, NoSuchMethodException, ConstructionFailedException {
Class<?> targetClass = com.examples.with.different.packagename.generic.GenericMethodReturningTypeVariable.class;
Method targetMethod = targetClass.getMethod("get", new Class<?>[] { Object.class });
GenericMethod genericMethod = new GenericMethod(targetMethod, targetClass);
GenericClass generatedType1 = new GenericClass(Integer.class);
GenericClass generatedType2 = new GenericClass(String.class);
GenericMethod instantiatedMethod = genericMethod.getGenericInstantiationFromReturnValue(generatedType2);
Assert.assertEquals(instantiatedMethod.getGeneratedClass().getRawClass(), String.class);
instantiatedMethod = genericMethod.getGenericInstantiationFromReturnValue(generatedType1);
Assert.assertEquals(instantiatedMethod.getGeneratedClass().getRawClass(), Integer.class);
}
Aggregations