public abstract class Specification extends MockingApi
Constructor and Description |
---|
Specification() |
Modifier and Type | Method and Description |
---|---|
void |
noExceptionThrown()
Specifies that no exception should be thrown, failing with a
UnallowedExceptionThrownError otherwise. |
void |
notThrown(Class<? extends Throwable> type)
Specifies that no exception of the given type should be
thrown, failing with a
UnallowedExceptionThrownError otherwise. |
<T> T |
old(T expression)
Used in a then-block to access an expression's value at the time just
before the previous where-block was entered.
|
<T extends Throwable> |
thrown()
Specifies that the preceding when block should throw an exception.
|
<T extends Throwable> |
thrown(Class<T> type)
Specifies that the preceding when block should throw an exception
of the given type.
|
void |
with(Object object,
Closure closure) |
GroovyMock, GroovyMock, GroovyMock, GroovyMock, GroovyMock, GroovyMock, GroovyMock, GroovyMock, GroovySpy, GroovySpy, GroovySpy, GroovySpy, GroovySpy, GroovySpy, GroovySpy, GroovySpy, GroovyStub, GroovyStub, GroovyStub, GroovyStub, GroovyStub, GroovyStub, GroovyStub, GroovyStub, interaction, Mock, Mock, Mock, Mock, Mock, Mock, Mock, Mock, Spy, Spy, Spy, Spy, Spy, Spy, Spy, Spy, Stub, Stub, Stub, Stub, Stub, Stub, Stub, Stub
public static final Object _
public <T extends Throwable> T thrown()
This form of exception condition is typically used if the thrown exception instance is used in subsequent conditions.
Example:
when: "".charAt(0) then: IndexOutOfBoundsException e = thrown() e.message.contains(...)
public <T extends Throwable> T thrown(Class<T> type)
This form of exception condition is typically used if the thrown exception instance is not used in subsequent conditions.
Example:
when: "".charAt(0) then: thrown(IndexOutOfBoundsException)
T
- the expected exception typetype
- the expected exception typepublic void notThrown(Class<? extends Throwable> type)
UnallowedExceptionThrownError
otherwise.type
- the exception type that should not be thrownpublic void noExceptionThrown()
UnallowedExceptionThrownError
otherwise.public <T> T old(T expression)
T
- the expression's typeexpression
- an arbitrary expression, except that it may not
reference variables defined in the then-block