Given:
DummyRequest.groovy
class DummyRequest {
final List<Session> sessions
DummyRequest (){
sessions=[
new Session(name: 'dave')
]
}
}
we can inject an empty 'sessions' field even though it was declared 'final' and set in the constructor:
class DummySpec extends Specification {
def "test sessions" () {
given:
DummyRequest req = GroovyStub(sessions: []) {}
expect:
req.sessions == []
}
}
Given:
DummyRequest.groovywe can inject an empty 'sessions' field even though it was declared 'final' and set in the constructor: