Package randoop.test

Class ExpectedExceptionGenerator

java.lang.Object
randoop.test.TestCheckGenerator
randoop.test.ExpectedExceptionGenerator

public class ExpectedExceptionGenerator extends TestCheckGenerator
A TestCheckGenerator that generates checks for exceptions that are expected at the final statement of a sequence. Creates a ExpectedExceptionCheck that is returned in a RegressionChecks collection if the exception occurs, or a ErrorRevealingChecks collection if not.

Note that this generator is distinct from other check generators that either return regression checks or error-revealing checks.

  • Field Details

    • 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 Details

    • ExpectedExceptionGenerator

      public ExpectedExceptionGenerator(List<List<ThrowsClause>> exceptionSets)
      Creates an ExpectedExceptionGenerator for the list of sets of expected exceptions.
      Parameters:
      exceptionSets - a list of lists of expected exceptions to be searched when testing an exception thrown by the operation in the final statement of the sequence. Each list of expected exceptions must be satisfied.
  • Method Details

    • generateTestChecks

      public TestChecks<?> generateTestChecks(ExecutableSequence eseq)
      Generate a TestChecks object for the executed sequence eseq based on the criteria of this generator.

      Adds checks for an expected exception at the final statement of the sequence.

      Specified by:
      generateTestChecks in class TestCheckGenerator
      Parameters:
      eseq - the sequence for which checks are generated
      Returns:
      the generated check set for the sequence
    • findMatchingExpectedType

      private static ClassOrInterfaceType findMatchingExpectedType(ClassOrInterfaceType throwableType, List<ThrowsClause> throwsClauses)
      Find the first ThrowsClause whose exception is a supertype of (or equal to) throwableType, and return that exception type.
      Parameters:
      throwableType - the type to search for
      throwsClauses - the ThrowsClauses to search within
      Returns:
      the type in the first matching ThrowsClause, or null if none match
    • getMissingExceptionTestChecks

      private ErrorRevealingChecks getMissingExceptionTestChecks(int finalIndex)
      Return an ErrorRevealingChecks that checks for a missing exception at the given index.
      Parameters:
      finalIndex - the index
      Returns:
      the ErrorRevealingChecks object
    • getExpected

      public List<List<ThrowsClause>> getExpected()
      Returns the types of the expected exceptions. Each list of throwsclauses represents one specification, and each such list must be satisfied.
      Returns:
      the types of the expected exceptions