Package randoop.test

Class ExpectedExceptionCheck

  • All Implemented Interfaces:
    Check

    public class ExpectedExceptionCheck
    extends ExceptionCheck
    An ExceptionCheck that enforces the expectation of an exception being thrown. In particular,
    • fails if exception is not thrown, and
    • succeeds only when expected exception is thrown.
    • Constructor Detail

      • ExpectedExceptionCheck

        public ExpectedExceptionCheck​(Throwable exception,
                                      int statementIndex,
                                      String catchClassName)
        Creates check that enforces expectation that an exception is thrown by the statement at the statement index.

        These are created before the test is classified as normal, exceptional, or invalid behavior. For example, this could be created with a TimeoutException, but the sequence would later be classified as invalid.

        Parameters:
        exception - the expected exception
        statementIndex - the index of the statement in the sequence where exception is thrown
        catchClassName - the name of exception to be caught
    • Method Detail

      • appendTryBehavior

        protected void appendTryBehavior​(StringBuilder b)
        Appends code to follow the statement throwing expected exception in try block.

        Appends a fail assertion after statement in try block.

        Specified by:
        appendTryBehavior in class ExceptionCheck
        Parameters:
        b - the string builder to which code text is added
      • toAscii

        private @PolyNull String toAscii​(@PolyNull String str)
        Converts the given string to ASCII. Replaces non-ASCII characters by an ASCII equivalent or by "?".
        Parameters:
        str - the string to convert to ASCII
        Returns:
        the string converted to ASCII
      • appendCatchBehavior

        protected void appendCatchBehavior​(StringBuilder b)
        Appends code for catch block behavior corresponding to an expected exception.

        Appends assertion to confirm expected exception caught.

        Specified by:
        appendCatchBehavior in class ExceptionCheck
        Parameters:
        b - the string builder to which code text is to be added