Skip to content

Groovy Mocks do not support isProperty() style getters for booleans #1270

Closed

Description

@mlasevich

Related, (but not the same as) #1256

When testing using a GroovyMock/GroovyStub/GroovySpy - isProperty() style getters are not respected, and only getProperty() is used.

Tested under org.spockframework:spock-core:1.3-groovy-2.4

To reproduce:

import spock.lang.Specification

class TesterSpec extends Specification {

  static class Tester {

    boolean isEnabled() {
      return true
    }
  }

  def 'Works'() {
    given:
      Tester x = new Tester()
    expect:
      x.enabled == true
  }

  def 'GroovySpy does not work Test'() {
    given:
      Tester x = GroovySpy(Tester)
    expect:
      x.enabled == true
  }

  def 'GroovyMock does not work either Test'(){
    given:
      Tester x = GroovyMock(Tester)
    when:
      x.enabled
    then:
      1 * x.isEnabled() >> true
  }

  def 'Mock works though Test'(){
    given:
      Tester x = Mock(Tester)
    when:
      x.enabled
    then:
      1 * x.isEnabled() >> true
  }
}

Activity

  1. kriegaex commented on Jan 31, 2021

    @kriegaex
    Contributor

    Like I said in the other issue, the same thing happens in Spock 2.0-M4 and in the master branch after #1256 was merged in already.

  2. added a commit that references this issue on Mar 21, 2021
    00cbf5f
  3. added a commit that references this issue on Mar 21, 2021
    4e2674a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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