public class ExpectedOutcomeTable
extends java.lang.Object
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 the Precondition
, the
GuardPropertyPair
, and GuardThrowsPair
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:
Precondition
fails, or all are satisfied.
ThrowsCondition
objects for expected
exceptions. An exception is expected if the guard of a GuardThrowsPair
is
satisfied.
ExecutableBooleanExpression
), if any.
To create an ExpectedOutcomeTable, call ExecutableSpecification.checkPrestate(Object[])
. To use an ExpectedOutcomeTable, call addPostCheckGenerator(TestCheckGenerator)
to create a TestCheckGenerator
that
classifies a method call as follows:
GenInputsAbstract.BehaviorType.EXPECTED
.
GenInputsAbstract.BehaviorType.ERROR
(because
the specification required an exception to be thrown, but it was not thrown).
GenInputsAbstract.BehaviorType.ERROR
.
GenInputsAbstract.BehaviorType.INVALID
.
GenInputsAbstract.BehaviorType.ERROR
.
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.util.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 java.util.List<ExecutableBooleanExpression> |
postConditions
The list of post-conditions whose guard expression was satisfied.
|
Constructor and Description |
---|
ExpectedOutcomeTable()
Creates an empty
ExpectedOutcomeTable . |
Modifier and Type | Method and Description |
---|---|
(package private) void |
add(boolean guardIsSatisfied,
ExecutableBooleanExpression postcondition,
java.util.List<ThrowsClause> throwsClauses)
Adds one operation to this table.
|
TestCheckGenerator |
addPostCheckGenerator(TestCheckGenerator gen)
Constructs the
TestCheckGenerator that will test for expected ThrowsClause s or
postconditions as follows:
If this table is empty, returns the given generator. |
boolean |
isInvalidCall()
Indicate whether the call should be classified as
GenInputsAbstract.BehaviorType.INVALID .) |
java.lang.String |
toString() |
private boolean isEmpty
private boolean hasSatisfiedPrecondition
private final java.util.List<ExecutableBooleanExpression> postConditions
private final java.util.List<java.util.List<ThrowsClause>> exceptionSets
public ExpectedOutcomeTable()
ExpectedOutcomeTable
.void add(boolean guardIsSatisfied, ExecutableBooleanExpression postcondition, java.util.List<ThrowsClause> throwsClauses)
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-statepublic boolean isInvalidCall()
GenInputsAbstract.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.
public TestCheckGenerator addPostCheckGenerator(TestCheckGenerator gen)
TestCheckGenerator
that will test for expected ThrowsClause
s or
postconditions as follows:
ExpectedExceptionGenerator
to check for those exceptions.
InvalidCheckGenerator
.
GuardPropertyPair
has a satisfied guard expression, then extend the given
generator with a PostConditionCheckGenerator
.
gen
- the generator to extendTestCheckGenerator
to check for expected outcomes in this tablepublic java.lang.String toString()
toString
in class java.lang.Object