use of org.evosuite.testcase.execution.TestCaseExecutor.TimeoutExceeded in project evosuite by EvoSuite.
the class HashCodeReturnsNormallyContract method check.
/* (non-Javadoc)
* @see org.evosuite.contracts.Contract#check(org.evosuite.testcase.Statement, org.evosuite.testcase.Scope, java.lang.Throwable)
*/
/**
* {@inheritDoc}
*/
@Override
public ContractViolation check(Statement statement, Scope scope, Throwable exception) {
for (VariableReference var : getAllVariables(scope)) {
Object object = scope.getObject(var);
if (object == null)
continue;
// We do not want to call hashCode if it is the default implementation
Class<?>[] parameters = {};
try {
Method equalsMethod = object.getClass().getMethod("hashCode", parameters);
if (equalsMethod.getDeclaringClass().equals(Object.class))
continue;
} catch (SecurityException e1) {
continue;
} catch (NoSuchMethodException e1) {
continue;
}
try {
// hashCode must not throw an exception
object.hashCode();
} catch (Throwable t) {
if (!(t instanceof TimeoutExceeded))
return new ContractViolation(this, statement, t, var);
}
}
return null;
}
use of org.evosuite.testcase.execution.TestCaseExecutor.TimeoutExceeded in project evosuite by EvoSuite.
the class ToStringReturnsNormallyContract method check.
/* (non-Javadoc)
* @see org.evosuite.contracts.Contract#check(org.evosuite.testcase.TestCase, org.evosuite.testcase.Statement, org.evosuite.testcase.Scope, java.lang.Throwable)
*/
/**
* {@inheritDoc}
*/
@Override
public ContractViolation check(Statement statement, Scope scope, Throwable exception) {
for (VariableReference var : getAllVariables(scope)) {
logger.debug("Current variable: " + var);
Object object = scope.getObject(var);
if (object == null) {
logger.debug("Current object is null");
continue;
}
// We do not want to call toString if it is the default implementation
Class<?>[] parameters = {};
try {
Method equalsMethod = object.getClass().getMethod("toString", parameters);
if (equalsMethod.getDeclaringClass().equals(Object.class))
continue;
} catch (SecurityException e1) {
continue;
} catch (NoSuchMethodException e1) {
continue;
}
try {
// toString must not throw an exception
object.toString();
} catch (Throwable t) {
if (!(t instanceof TimeoutExceeded)) {
logger.debug("Violation found");
return new ContractViolation(this, statement, t, var);
} else {
logger.debug("Timeout");
}
}
}
return null;
}
Aggregations