Search in sources :

Example 86 with GenericMethod

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);
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod) Test(org.junit.Test)

Example 87 with GenericMethod

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());
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) GenericMethod(org.evosuite.utils.generic.GenericMethod) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 88 with GenericMethod

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());
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod) Test(org.junit.Test)

Example 89 with GenericMethod

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);
}
Also used : GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod) GenericClass(org.evosuite.utils.generic.GenericClass) TypeToken(com.googlecode.gentyref.TypeToken) Test(org.junit.Test)

Example 90 with GenericMethod

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);
}
Also used : GenericClass(org.evosuite.utils.generic.GenericClass) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod) Test(org.junit.Test)

Aggregations

GenericMethod (org.evosuite.utils.generic.GenericMethod)110 Test (org.junit.Test)68 VariableReference (org.evosuite.testcase.variable.VariableReference)64 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)60 Method (java.lang.reflect.Method)57 GenericClass (org.evosuite.utils.generic.GenericClass)40 MethodStatement (org.evosuite.testcase.statements.MethodStatement)29 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)19 ArrayList (java.util.ArrayList)18 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)17 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)15 TestCase (org.evosuite.testcase.TestCase)12 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)11 Injector (org.evosuite.runtime.javaee.injection.Injector)10 Type (java.lang.reflect.Type)9 ConstructionFailedException (org.evosuite.ga.ConstructionFailedException)8 EvoServletState (org.evosuite.runtime.javaee.javax.servlet.EvoServletState)8 GenericAccessibleObject (org.evosuite.utils.generic.GenericAccessibleObject)8 GenericField (org.evosuite.utils.generic.GenericField)8 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)7