What is the difference in a mocked instance between getProperty('name') vs getName()? I thought they meant the same thing but I keep having to swap between them because sometimes spock isn't happy with one or the other.
Let's say I have the following class
class Person {
String name
}
And I'm testing some other class that is meant to update the person so I do something like this:
void "test something"() {
Person personMock = Mock(Person)
when:
someObject.updatePersonName(personMock, 'new name')
then:
1 * personMock.getName() >> 'old name'
1 * personMock.setName('new name')
}
The details of the simplified test aren't important. The point is that I'm verifying that a certain property is being read and updated. Sometimes when I run the tests I get complaints that personMock.getName() was never called and it helpfully shows that personMock.getProperty('name') was called instead. The test passes if I rewrite it to use that form. Until some time later it again complains that getProperty('name') wasn't called but getName() was.
I know that spock can't possibly be this flaky. I must have fumbled somewhere. So when should I use getName() and when getProperty('name')?