use of org.evosuite.testcase.variable.FieldReference in project evosuite by EvoSuite.
the class ContractViolation method same.
/**
* Determine if we have already seen an instance of this violation
*
* @param other
* a {@link org.evosuite.contracts.ContractViolation} object.
* @return a boolean.
*/
public boolean same(ContractViolation other) {
// Same contract?
if (!contract.getClass().equals(other.contract.getClass()))
return false;
// Same type of statement?
if (!statement.getClass().equals(other.statement.getClass()))
return false;
// Same exception type?
if (exception != null && other.exception != null) {
if (!exception.getClass().equals(other.exception.getClass()))
return false;
}
// Same method call / constructor?
if (statement instanceof MethodStatement) {
MethodStatement ms1 = (MethodStatement) statement;
MethodStatement ms2 = (MethodStatement) other.statement;
if (ms1.getMethod().getMethod().equals(ms2.getMethod().getMethod())) {
return true;
}
} else if (statement instanceof ConstructorStatement) {
ConstructorStatement ms1 = (ConstructorStatement) statement;
ConstructorStatement ms2 = (ConstructorStatement) other.statement;
if (ms1.getConstructor().getConstructor().equals(ms2.getConstructor().getConstructor())) {
return true;
}
} else if (statement instanceof AssignmentStatement) {
VariableReference var1 = statement.getReturnValue();
VariableReference var2 = other.statement.getReturnValue();
if (var1 instanceof FieldReference && var2 instanceof FieldReference) {
if (((FieldReference) var1).getField().getField().equals(((FieldReference) var2).getField().getField()))
return true;
}
}
return false;
}
use of org.evosuite.testcase.variable.FieldReference in project evosuite by EvoSuite.
the class DowncastTest method testFieldReferenceDoesNotNeedDowncast.
@Test
public void testFieldReferenceDoesNotNeedDowncast() throws NoSuchMethodException, NoSuchFieldException {
TestCaseBuilder builder = new TestCaseBuilder();
VariableReference var = builder.appendConstructor(DowncastExample.class.getConstructor());
VariableReference num0 = builder.appendMethod(var, DowncastExample.class.getMethod("getAbstractFoo"));
// This would be set during execution
num0.setType(ConcreteSubclass.class);
VariableReference bool0 = builder.appendBooleanPrimitive(true);
DefaultTestCase test = builder.getDefaultTestCase();
FieldReference fr = new FieldReference(test, new GenericField(AbstractSuperclass.class.getField("fieldInAbstractClass"), AbstractSuperclass.class), num0);
AssignmentStatement statement = new AssignmentStatement(test, fr, bool0);
test.addStatement(statement);
test.removeDownCasts();
System.out.println(test);
FieldReference fr2 = (FieldReference) test.getStatement(3).getReturnValue();
assertEquals(AbstractSuperclass.class, fr2.getSource().getVariableClass());
}
Aggregations