randoop
Interface ObjectContract

All Superinterfaces:
Serializable
All Known Implementing Classes:
CheckRepContract, EqualsHashcode, EqualsReflexive, EqualsSymmetric, EqualsToNullRetFalse, HashCodeReturnsNormally, IsNotNull, IsNull, ObserverEqValue, PrimValue, ToStringReturnsNormally

public interface ObjectContract
extends Serializable

An object contract provides the core functionality for the checking code of unit tests, i.e. the code that checks for expected behavior. An object contract checks a specific property for one or more objects. Implementing classes provide two key pieces functionality:

Randoop outputs sequences that lead to failing properties as error-revealing test cases.

See the various implementing classes for examples (for an example, see the EqualsReflexive).


Method Summary
Modifier and Type Method and Description
 boolean evalExceptionMeansFailure()
          Communicates to Randoop how to interpret exceptional behavior from the evaluate method.
 boolean evaluate(Object... objects)
          Evaluates the contract on the given values.
 String get_observer_str()
          Returns a string describing the observer
 int getArity()
          The number of values that this contract is over.
 String toCodeString()
          A string that can be used as Java source code and will result in the expression being evaluated.
 String toCommentString()
          A string that will be inserted as a comment in the test before the code corresponding to this contract.
 

Method Detail

getArity

int getArity()
The number of values that this contract is over.


evaluate

boolean evaluate(Object... objects)
                 throws Throwable
Evaluates the contract on the given values.

When calling this method during execution of a test, Randoop guarantees that objects does not contain any null objects, and that objects.length == getArity().

This method should return true if the contract was satisfied and false if it was violated.

Throws:
Throwable

evalExceptionMeansFailure

boolean evalExceptionMeansFailure()
Communicates to Randoop how to interpret exceptional behavior from the evaluate method.

If this method returns true, Randoop will interpret an exception that escapes during evaluation as a failure of the contract.

If the method returns false, Randoop will interpret an exception as passing behavior.


toCommentString

String toCommentString()
A string that will be inserted as a comment in the test before the code corresponding to this contract.


toCodeString

String toCodeString()
A string that can be used as Java source code and will result in the expression being evaluated.

The string should be formatted as follows: the N-th object that participates in the contract check should be referred to as "xN" (for N one of 0, ... , 9). For example, if the expression or arity 2 represents a call of the equals method between two objects, the comment should be something like "x0.equals(x1)".

The returned string should not be null.


get_observer_str

String get_observer_str()
Returns a string describing the observer