public abstract class ExceptionCheck extends java.lang.Object implements Check
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(java.lang.StringBuilder)
and appendCatchBehavior(java.lang.StringBuilder)
which handle differences in whether
assertions are generated to enforce the expectation of the exception.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
catchClassName
The name of exception to be caught.
|
protected java.lang.Throwable |
exception
The thrown exception.
|
(package private) int |
statementIndex
Indicates which statement results in the given exception.
|
Modifier | Constructor and Description |
---|---|
protected |
ExceptionCheck(java.lang.Throwable exception,
int statementIndex,
java.lang.String catchClassName)
Creates an exception check for the statement at the statement index.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
appendCatchBehavior(java.lang.StringBuilder b)
Appends code for catch block behavior corresponding to an expected exception.
|
protected abstract void |
appendTryBehavior(java.lang.StringBuilder b)
Appends code to follow the statement throwing expected exception in try block.
|
boolean |
equals(@Nullable java.lang.Object o)
Determines if two
ExceptionCheck objects are equal. |
java.lang.Throwable |
getException()
Returns the exception.
|
@Nullable java.lang.String |
getExceptionName()
Returns the name of the exception class.
|
int |
hashCode() |
java.lang.String |
toCodeStringPostStatement()
Returns a string of Java source code to be emitted after a statement containing this check.
|
java.lang.String |
toCodeStringPreStatement()
Returns a string of Java source code to be emitted before a statement containing this check.
|
java.lang.String |
toString() |
protected final java.lang.Throwable exception
final int statementIndex
private java.lang.String catchClassName
exception
's class C,
for instance because C is private or because the method is declared to throw a superclass of C.protected ExceptionCheck(java.lang.Throwable exception, int statementIndex, java.lang.String catchClassName)
exception
- the exception expected at the statement indexstatementIndex
- the position of the statement in a sequencecatchClassName
- the name of exception to be caughtpublic boolean equals(@Nullable java.lang.Object o)
ExceptionCheck
objects are equal. Assumes that implementing classes
have no state.equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public final java.lang.String toCodeStringPreStatement()
The pre-statement prefix of the try-catch wrapper.
toCodeStringPreStatement
in interface Check
public final java.lang.String toCodeStringPostStatement()
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 of appendCatchBehavior(java.lang.StringBuilder)
. Catches this exception or the closest public superclass of the
exception.
toCodeStringPostStatement
in interface Check
protected abstract void appendCatchBehavior(java.lang.StringBuilder b)
b
- the string builder to which code text is to be addedprotected abstract void appendTryBehavior(java.lang.StringBuilder b)
b
- the string builder to which code text is addedpublic @Nullable java.lang.String getExceptionName()
public java.lang.Throwable getException()