caffinc / statiflex

Change static final values in Java
MIT License
1 stars 0 forks source link

Spock can do this btw #1

Open davidmoshal opened 7 years ago

davidmoshal commented 7 years ago

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 == []
  }
}
SriramKeerthi commented 6 years ago

I'm not sure I follow. Do you want to change the value of a final field, instead of just static final?

SriramKeerthi commented 6 years ago

Sorry about the super slow response by the way :) This got buried under tons of other notifications so I never noticed it.