Class ExceptionCheck
- All Implemented Interfaces:
Check
- Direct Known Subclasses:
EmptyExceptionCheck
,ExpectedExceptionCheck
,InvalidExceptionCheck
ExceptionCheck
indicates that an exception is expected at a particular statement in a
sequence.
When test code is generated in ExecutableSequence.toCodeString()
, the
methods toCodeStringPreStatement()
and toCodeStringPostStatement()
wrap the
statement in a try-catch block for the exception, while the implementing classes define appendTryBehavior(StringBuilder)
and appendCatchBehavior(StringBuilder)
which handle
differences in whether assertions are generated to enforce the expectation of the exception.
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
ExceptionCheck
(Throwable exception, int statementIndex, String catchClassName) Creates an exception check for the statement at the statement index. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
Appends code for catch block behavior corresponding to expected exception.protected abstract void
Appends code to follow the statement throwing expected exception in try block.boolean
Determines if twoExceptionCheck
objects are equal.Returns the exception.Returns the name of the exception class.int
hashCode()
final String
Returns a string of Java source code to be emitted after a statement containing this check.final String
Returns a string of Java source code to be emitted before a statement containing this check.toString()
-
Field Details
-
exception
The thrown exception. -
statementIndex
final int statementIndexIndicates which statement results in the given exception. -
catchClassName
The name of exception to be caught. This might be a supertype ofexception
's class C, for instance because C is private or because the method is declared to throw a superclass of C.
-
-
Constructor Details
-
ExceptionCheck
Creates an exception check for the statement at the statement index. The generated code for this check will include a try-catch block with behaviors determined by implementing sub-classes.- Parameters:
exception
- the exception expected at the statement indexstatementIndex
- the position of the statement in a sequencecatchClassName
- the name of exception to be caught
-
-
Method Details
-
equals
Determines if twoExceptionCheck
objects are equal. Assumes that implementing classes have no state. -
hashCode
public int hashCode() -
toString
-
toCodeStringPreStatement
Returns a string of Java source code to be emitted before a statement containing this check.The pre-statement prefix of the try-catch wrapper.
- Specified by:
toCodeStringPreStatement
in interfaceCheck
- Returns:
- the string to be included before the statement
-
toCodeStringPostStatement
Returns a string of Java source code to be emitted after a statement containing this check.Returns the post-statement portion of the try-catch wrapper. Starts with post-statement try-behavior as determined by a subclass implementation of
appendTryBehavior(java.lang.StringBuilder)
, and then closes with the catch clause with the body determined by the sub-class implementation ofappendCatchBehavior(StringBuilder)
. Catches this exception or the closest public superclass of the exception.- Specified by:
toCodeStringPostStatement
in interfaceCheck
- Returns:
- the post-statement code text for the expected exception
-
appendCatchBehavior
Appends code for catch block behavior corresponding to expected exception.- Parameters:
b
- the string builder to which code text is to be added
-
appendTryBehavior
Appends code to follow the statement throwing expected exception in try block.- Parameters:
b
- the string builder to which code text is added
-
getExceptionName
Returns the name of the exception class.- Returns:
- the canonical name of the exception class
-
getException
Returns the exception.- Returns:
- the exception in this check
-