I have got a strange use case where spock mock is returning the correct value when I do not check for two calls on the mocked class in the 'then:' section, but it is returning 0 when I include two checks in the 'then:' section. This is the mock:
mockDao.readCounter(_, _, _, _, _) >> dbValue
and here is the 'then:' section that fails:
1 * mockDao.readCounter(_, _, _, _, _)
// updateCounters is called with: sum = dbValue + value
1 * mockDao.updateCounter(namespace, date, key, min, shardID, dbValue + value)
In this case, instead of 'dbValue', '0' is returned. But if I comment out either of the two checks, then it passes. So, the following two cases pass:
//1 * mockDao.readCounter(_, _, _, _, _)
// updateCounters is called with: sum = dbValue + value
1 * mockDao.updateCounter(namespace, date, key, min, shardID, dbValue + value)
OR
1 * mockDao.readCounter(_, _, _, _, _)
// updateCounters is called with: sum = dbValue + value
//1 * mockDao.updateCounter(namespace, date, key, min, shardID, dbValue + value)
Here is the gradle section for spock:
// spock
testCompile "org.codehaus.groovy:groovy:2.4.7"
compile group: 'org.spockframework', name: 'spock-core', version: '1.0-groovy-2.4'
// !!! To get none-interface base mocking to work with Spock
compile group: 'cglib', name: 'cglib-nodep', version: '3.2.4'