Package randoop.test
Class ExpectedExceptionCheck
- java.lang.Object
-
- randoop.test.ExceptionCheck
-
- randoop.test.ExpectedExceptionCheck
-
- All Implemented Interfaces:
Check
public class ExpectedExceptionCheck extends ExceptionCheck
AnExceptionCheck
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.
-
-
Field Summary
-
Fields inherited from class randoop.test.ExceptionCheck
exception, statementIndex
-
-
Constructor Summary
Constructors Constructor Description ExpectedExceptionCheck(Throwable exception, int statementIndex, String catchClassName)
Creates check that enforces expectation that an exception is thrown by the statement at the statement index.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
appendCatchBehavior(StringBuilder b)
Appends code for catch block behavior corresponding to an expected exception.protected void
appendTryBehavior(StringBuilder b)
Appends code to follow the statement throwing expected exception in try block.private @PolyNull String
toAscii(@PolyNull String str)
Converts the given string to ASCII.-
Methods inherited from class randoop.test.ExceptionCheck
equals, getException, getExceptionName, hashCode, toCodeStringPostStatement, toCodeStringPreStatement, toString
-
-
-
-
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 exceptionstatementIndex
- the index of the statement in the sequence where exception is throwncatchClassName
- 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 classExceptionCheck
- 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 classExceptionCheck
- Parameters:
b
- the string builder to which code text is to be added
-
-