use of org.evosuite.testcase.statements.ConstructorStatement in project evosuite by EvoSuite.
the class Contract method isTargetStatement.
/**
* Check if this statement is related to the unit under test
*
* @param statement
* a {@link org.evosuite.testcase.statements.Statement} object.
* @return a boolean.
*/
protected boolean isTargetStatement(Statement statement) {
// return true;
if (statement instanceof MethodStatement) {
MethodStatement ms = (MethodStatement) statement;
final Class<?> targetClass = Properties.getTargetClassAndDontInitialise();
if (targetClass.equals(ms.getMethod().getDeclaringClass()))
return true;
} else if (statement instanceof ConstructorStatement) {
ConstructorStatement cs = (ConstructorStatement) statement;
final Class<?> targetClass = Properties.getTargetClassAndDontInitialise();
if (targetClass.equals(cs.getConstructor().getDeclaringClass()))
return true;
} else if (statement instanceof FieldStatement) {
FieldStatement fs = (FieldStatement) statement;
final Class<?> targetClass = Properties.getTargetClassAndDontInitialise();
if (targetClass.equals(fs.getField().getDeclaringClass()))
return true;
}
return false;
}
use of org.evosuite.testcase.statements.ConstructorStatement in project evosuite by EvoSuite.
the class ExceptionCoverageHelper method getMethodIdentifier.
public static String getMethodIdentifier(ExecutionResult result, int exceptionPosition) {
if (result.test.getStatement(exceptionPosition) instanceof MethodStatement) {
MethodStatement ms = (MethodStatement) result.test.getStatement(exceptionPosition);
Method method = ms.getMethod().getMethod();
return method.getName() + Type.getMethodDescriptor(method);
} else if (result.test.getStatement(exceptionPosition) instanceof ConstructorStatement) {
ConstructorStatement cs = (ConstructorStatement) result.test.getStatement(exceptionPosition);
Constructor<?> constructor = cs.getConstructor().getConstructor();
return "<init>" + Type.getConstructorDescriptor(constructor);
}
return "";
}
use of org.evosuite.testcase.statements.ConstructorStatement in project evosuite by EvoSuite.
the class ExceptionCoverageHelper method isSutException.
public static boolean isSutException(ExecutionResult result, int exceptionPosition) {
if (result.test.getStatement(exceptionPosition) instanceof MethodStatement) {
MethodStatement ms = (MethodStatement) result.test.getStatement(exceptionPosition);
Method method = ms.getMethod().getMethod();
Class<?> targetClass = Properties.getTargetClassAndDontInitialise();
if (method.getDeclaringClass().equals(targetClass)) {
return true;
}
} else if (result.test.getStatement(exceptionPosition) instanceof ConstructorStatement) {
ConstructorStatement cs = (ConstructorStatement) result.test.getStatement(exceptionPosition);
Constructor<?> constructor = cs.getConstructor().getConstructor();
Class<?> targetClass = Properties.getTargetClassAndDontInitialise();
if (constructor.getDeclaringClass().equals(targetClass)) {
return true;
}
}
return false;
}
use of org.evosuite.testcase.statements.ConstructorStatement in project evosuite by EvoSuite.
the class ControlFlowDistanceCalculator method hasConstructorException.
/**
* If there is an exception in a superconstructor, then the corresponding
* constructor might not be included in the execution trace
*
* @param results
* @param callCount
*/
private static boolean hasConstructorException(ExecutionResult result, String className, String methodName) {
if (result.hasTimeout() || result.hasTestException() || result.noThrownExceptions())
return false;
Integer exceptionPosition = result.getFirstPositionOfThrownException();
if (!result.test.hasStatement(exceptionPosition)) {
return false;
}
Statement statement = result.test.getStatement(exceptionPosition);
if (statement instanceof ConstructorStatement) {
ConstructorStatement c = (ConstructorStatement) statement;
String constructorClassName = c.getConstructor().getName();
String constructorMethodName = "<init>" + Type.getConstructorDescriptor(c.getConstructor().getConstructor());
if (constructorClassName.equals(className) && constructorMethodName.equals(methodName)) {
return true;
}
}
return false;
}
use of org.evosuite.testcase.statements.ConstructorStatement in project evosuite by EvoSuite.
the class TestSimilarity method testBasicSimilarityDifferentTypes2.
@Test
public void testBasicSimilarityDifferentTypes2() {
TestCase test1 = new DefaultTestCase();
TestCase test2 = new DefaultTestCase();
PrimitiveStatement<?> aInt = new LongPrimitiveStatement(test1, 42L);
test1.addStatement(aInt);
PrimitiveStatement<?> aInt2 = new IntPrimitiveStatement(test1, 42);
test1.addStatement(aInt2);
PrimitiveStatement<?> bInt = new IntPrimitiveStatement(test2, 42);
test2.addStatement(bInt);
Constructor<?> c = Object.class.getConstructors()[0];
ConstructorStatement cs = new ConstructorStatement(test2, new GenericConstructor(c, Object.class), new ArrayList<VariableReference>());
test2.addStatement(cs);
double score = DiversityObserver.getNeedlemanWunschScore(test1, test2);
Assert.assertTrue(score <= 0);
}
Aggregations