randoop
Class ObserverEqValue

Object
  extended by ObserverEqValue
All Implemented Interfaces:
Serializable, ObjectContract

public final class ObserverEqValue
extends Object
implements ObjectContract

A check recording the value that an observer method returned during execution, e.g. a check recording that a collection's size() method returned 3 when called in particular sequence.

ObserverEqValue checks are not checks that must hold of all objects of a given class (unlike a check like EqualsReflexive, which must hold for any objects, no matter its execution context). Randoop creates an instance of this contract when, during execution of a sequence, it determines that the above property holds. The property thus represents a regression as it captures the behavior of the code when it is executed.

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
 Method observer
          The observer method.
 Object value
          The runtime value of the observer.
 
Constructor Summary
Constructor and Description
ObserverEqValue(Method observer, Object value)
           
 
Method Summary
Modifier and Type Method and Description
 boolean equals(Object o)
           
 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.
static ObserverEqValue getObserverEqValue(Method method, Object val)
          Create an ObserverEqValue from its basic parts (used when reading from a serialized file).
 int hashCode()
           
 String toCodeString()
          A string that can be used as Java source code and will result in the expression being evaluated.
 String toCodeStringPreStatement()
           
 String toCommentString()
          A string that will be inserted as a comment in the test before the code corresponding to this contract.
 String toString()
           
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

observer

public Method observer
The observer method.


value

public Object value
The runtime value of the observer. This variable holds a primitive value or String.

Constructor Detail

ObserverEqValue

public ObserverEqValue(Method observer,
                       Object value)
Method Detail

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toCodeStringPreStatement

public String toCodeStringPreStatement()

toCodeString

public String toCodeString()
Description copied from interface: ObjectContract
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.

Specified by:
toCodeString in interface ObjectContract

getObserverEqValue

public static ObserverEqValue getObserverEqValue(Method method,
                                                 Object val)
Create an ObserverEqValue from its basic parts (used when reading from a serialized file).


evaluate

public boolean evaluate(Object... objects)
                 throws Throwable
Description copied from interface: ObjectContract
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.

Specified by:
evaluate in interface ObjectContract
Throws:
Throwable

getArity

public int getArity()
Description copied from interface: ObjectContract
The number of values that this contract is over.

Specified by:
getArity in interface ObjectContract

toCommentString

public String toCommentString()
Description copied from interface: ObjectContract
A string that will be inserted as a comment in the test before the code corresponding to this contract.

Specified by:
toCommentString in interface ObjectContract

evalExceptionMeansFailure

public boolean evalExceptionMeansFailure()
Description copied from interface: ObjectContract
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.

Specified by:
evalExceptionMeansFailure in interface ObjectContract

get_observer_str

public String get_observer_str()
Description copied from interface: ObjectContract
Returns a string describing the observer

Specified by:
get_observer_str in interface ObjectContract

toString

public String toString()
Overrides:
toString in class Object