Skip to content

Spock can do this btw #1

@davidmoshal

Description

@davidmoshal

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 == []
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions