public class ExceptionMock extends Object implements InvocationHandler
assertSame()
).
To use, construct around the desired exception, and call getInstance(java.lang.Class<T>)
to create the stub. Since this class does not maintain any state (other than
the configured exception), you can create many stubs from a single mock.
Constructor and Description |
---|
ExceptionMock(Class<? extends Throwable> klass)
Creates a factory for stub objects that will throw new instances of the
specified exception class.
|
ExceptionMock(Throwable ex)
Creates a factory for stub objects that will always throw a specific
exception.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
getInstance(Class<T> classToMock) |
Object |
invoke(Object proxy,
Method method,
Object[] args) |
public ExceptionMock(Throwable ex)
public ExceptionMock(Class<? extends Throwable> klass)
Note: instances are created by reflection. If unable to create an exception instance (typically due to protection/missing class), will throw a reflection exception instead (and this will potentially be captured by the proxy and wrapped in a proxy exception).