Search in sources :

Example 1 with TimeoutExceeded

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;
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) TimeoutExceeded(org.evosuite.testcase.execution.TestCaseExecutor.TimeoutExceeded) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method)

Example 2 with TimeoutExceeded

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;
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) TimeoutExceeded(org.evosuite.testcase.execution.TestCaseExecutor.TimeoutExceeded) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method)

Aggregations

Method (java.lang.reflect.Method)2 TimeoutExceeded (org.evosuite.testcase.execution.TestCaseExecutor.TimeoutExceeded)2 VariableReference (org.evosuite.testcase.variable.VariableReference)2 GenericMethod (org.evosuite.utils.generic.GenericMethod)2