Class ExpectedOutcomeTable
- java.lang.Object
-
- randoop.condition.ExpectedOutcomeTable
-
public class ExpectedOutcomeTable extends Object
An ExpectedOutcomeTable collects all the permitted outcomes for a set of methods (where the methods are all in an overriding relationship) and a set of prestate values. The set of expected or permitted outcomes is those whose preconditions or conditions are satisfied.A method implementation must satisfy not only the specification written on it, but also any written on method declarations that it overrides or implements.
One possible implementation would be to record a collection of single-method outcomes, where each single-method outcome represents checks of the prestate
ExecutableBooleanExpression
s: for thePrecondition
, theGuardPropertyPair
, andGuardThrowsPair
for an operation call. ExpectedOutcomeTable is not implemented that way: it does some pre-processing and throws away certain of the information as it is added. (It's unclear whether this is the best choice, or whether the more straightforward implementation would enable simpler and more understandable code at the cost of a bit of extra processing to be done later.)This implementation records:
- Whether any guard expression for the
Precondition
fails, or all are satisfied. - The set of
ThrowsCondition
objects for expected exceptions. An exception is expected if the guard of aGuardThrowsPair
is satisfied. - The expected postcondition (an
ExecutableBooleanExpression
), if any.
To create an ExpectedOutcomeTable, call
ExecutableSpecification.checkPrestate(Object[])
. To use an ExpectedOutcomeTable, calladdPostCheckGenerator(TestCheckGenerator)
to create aTestCheckGenerator
that classifies a method call as follows:- For each table entry with a non-empty expected exception set
- If an exception is thrown by the call and the thrown exception is a member of the
set, then classify as
GenInputsAbstract.BehaviorType.EXPECTED
. - If an exception is thrown by the call and the thrown exception is not a member of the
set, classify as
GenInputsAbstract.BehaviorType.ERROR
(because the specification required an exception to be thrown, but it was not thrown). - If no exception is thrown, then classify as
GenInputsAbstract.BehaviorType.ERROR
.
- If an exception is thrown by the call and the thrown exception is a member of the
set, then classify as
- If for each table entry, the preconditions failed, classify as
GenInputsAbstract.BehaviorType.INVALID
. - For each table entry where all preconditions were satisfied, check the corresponding normal
post-condition property, if one exists. If any such property fails, then classify as
GenInputsAbstract.BehaviorType.ERROR
. - Otherwise, don't classify (let classification fall through).
- Whether any guard expression for the
-
-
Field Summary
Fields Modifier and Type Field Description private List<List<ThrowsClause>>
exceptionSets
The list of lists of throws clauses for which the guard expression was satisfied.private boolean
hasSatisfiedPrecondition
Indicates whether the precondition was satisfied for at least one row of the table.private boolean
isEmpty
Indicates whether this table is empty.private List<ExecutableBooleanExpression>
postConditions
The list of post-conditions whose guard expression was satisfied.
-
Constructor Summary
Constructors Constructor Description ExpectedOutcomeTable()
Creates an emptyExpectedOutcomeTable
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
add(boolean guardIsSatisfied, ExecutableBooleanExpression postcondition, List<ThrowsClause> throwsClauses)
Adds one operation to this table.TestCheckGenerator
addPostCheckGenerator(TestCheckGenerator gen)
Constructs theTestCheckGenerator
that will test for expectedThrowsClause
s or postconditions as follows: If this table is empty, returns the given generator.boolean
isInvalidCall()
Indicate whether the call should be classified asGenInputsAbstract.BehaviorType.INVALID
.)String
toString()
-
-
-
Field Detail
-
isEmpty
private boolean isEmpty
Indicates whether this table is empty.
-
hasSatisfiedPrecondition
private boolean hasSatisfiedPrecondition
Indicates whether the precondition was satisfied for at least one row of the table.
-
postConditions
private final List<ExecutableBooleanExpression> postConditions
The list of post-conditions whose guard expression was satisfied.
-
exceptionSets
private final List<List<ThrowsClause>> exceptionSets
The list of lists of throws clauses for which the guard expression was satisfied. Each list of throwsclauses represents one specification, and each such list must be satisfied.
-
-
Constructor Detail
-
ExpectedOutcomeTable
public ExpectedOutcomeTable()
Creates an emptyExpectedOutcomeTable
.
-
-
Method Detail
-
add
void add(boolean guardIsSatisfied, ExecutableBooleanExpression postcondition, List<ThrowsClause> throwsClauses)
Adds one operation to this table.- Parameters:
guardIsSatisfied
- boolean value indicating whether all guard expressions are satisfiedpostcondition
- property expression that must be true in post-state if no exception is thrownthrowsClauses
- set of<exception type, comment>
pairs for exceptions expected in post-state
-
isInvalidCall
public boolean isInvalidCall()
Indicate whether the call should be classified asGenInputsAbstract.BehaviorType.INVALID
.)Occurs when all guard expressions fail and there are no expected exceptions.
This method should be called after all entries are added; that is, no more entries should be added after it is called.
- Returns:
- true iff guard expressions of all specifications are unsatisfied, and there are no expected exceptions
-
addPostCheckGenerator
public TestCheckGenerator addPostCheckGenerator(TestCheckGenerator gen)
Constructs theTestCheckGenerator
that will test for expectedThrowsClause
s or postconditions as follows:- If this table is empty, returns the given generator.
- If this table has expected exceptions, then returns a
ExpectedExceptionGenerator
to check for those exceptions. - If all preconditions fail, then return an
InvalidCheckGenerator
. - if any
GuardPropertyPair
has a satisfied guard expression, then extend the given generator with aPostConditionCheckGenerator
.
- Parameters:
gen
- the generator to extend- Returns:
- the
TestCheckGenerator
to check for expected outcomes in this table
-
-