Class 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 ExecutableBooleanExpressions: 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:

    1. Whether any guard expression for the Precondition fails, or all are satisfied.
    2. The set of ThrowsCondition objects for expected exceptions. An exception is expected if the guard of a GuardThrowsPair is satisfied.
    3. The expected postcondition (an 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:

    1. For each table entry with a non-empty expected exception set
    2. If for each table entry, the preconditions failed, classify as GenInputsAbstract.BehaviorType.INVALID.
    3. 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.
    4. Otherwise, don't classify (let classification fall through).
    • 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.
      • 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

    • 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 satisfied
        postcondition - property expression that must be true in post-state if no exception is thrown
        throwsClauses - set of <exception type, comment> pairs for exceptions expected in post-state
      • isInvalidCall

        public boolean isInvalidCall()
        Indicate whether the call should be classified as 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.

        Returns:
        true iff guard expressions of all specifications are unsatisfied, and there are no expected exceptions