public abstract class ObjectContract
extends java.lang.Object
Implementing classes provide two key pieces functionality:
evaluate(java.lang.Object...)(Object... objects) that determines if the given
object(s) satisfy the property.
toCodeString()() that emits Java code that can be inserted into a
unit test to check for the given property.
See the various implementing classes for examples (for an example, see EqualsReflexive).
| Constructor and Description |
|---|
ObjectContract() |
| Modifier and Type | Method and Description |
|---|---|
Check |
checkContract(ExecutableSequence eseq,
java.lang.Object[] values)
Checks a contract on a particular array of values.
|
abstract boolean |
evaluate(java.lang.Object... objects)
Evaluates the contract on the given values.
|
(package private) ObjectCheck |
failedContract(ExecutableSequence eseq,
java.lang.Object[] values)
Return an ObjectCheck indicating that a contract failed.
|
abstract java.lang.String |
get_observer_str()
Returns a string describing the observer.
|
abstract int |
getArity()
The number of values that this contract is over.
|
abstract TypeTuple |
getInputTypes()
Returns the input types for this contract.
|
abstract java.lang.String |
toCodeString()
A string that can be used as Java source code and will result in the expression being
evaluated.
|
abstract java.lang.String |
toCommentString()
A string that will be inserted as a comment in the test before the code corresponding to this
contract.
|
(package private) static java.lang.String |
toStringHandleExceptions(java.lang.Object o) |
public abstract int getArity()
public abstract TypeTuple getInputTypes()
public abstract boolean evaluate(java.lang.Object... objects)
throws java.lang.Throwable
false if the contract was violated.
Returns true if the contract was satisfied or was not applicable.
When calling this method during execution of a test, Randoop guarantees that objects
does not contain any null objects, and that objects.length == getArity().
objects - the actual parameters to this contractjava.lang.Throwable - if an exception is thrown in evaluationpublic abstract java.lang.String toCommentString()
public abstract java.lang.String toCodeString()
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 of arity 2 represents a call of the equals
method between two objects, the code should be something like assert x0.equals(x1);".
The string does not contain a trailing newline. When there is a leading comment, it should start with a newline.
public abstract java.lang.String get_observer_str()
public final Check checkContract(ExecutableSequence eseq, java.lang.Object[] values)
eseq - the executable sequence that is the source of values for checking contractsvalues - the input valuesObjectCheck if the contract fails, an InvalidExceptionCheck if the
contract throws an exception indicating that the sequence is invalid, null otherwiseObjectCheck failedContract(ExecutableSequence eseq, java.lang.Object[] values)
eseq - the sequence for which a contract failedvalues - the input valuesstatic java.lang.String toStringHandleExceptions(java.lang.Object o)