Spock mock method implementation not working when checking invocations number

2 answers

I have a problem with mocking methods using Spock. Below is the code which I am using. Without any change everything is working - mock implementation work properly and returns "mock" string. However if I uncomment line with invocation check (3 * notifier.test()) my mock implementation for method notify is not invoking and tests fails because notifier mock returns null. Why it works like that?

class Aaaaa extends Specification {     class Notifier {         def test() {             println("Called in impl...")             return "impl"         }     }      def "Should verify notify was called"() {         given:         Notifier notifier = Mock(Notifier)         notifier.test() >> {             println("Called in mock...")             return "mock"         }          when:         notifier.test()         notifier.test()         def result = notifier.test()          then: //        3 * notifier.test()         result == "mock"     } } 

All answers to this question, which has the identifier 60542724

The best answer:

Mockito-style splitting of stubbing and mocking into two separate statements will not work

From docs: http://spockframework.org/spock/docs/1.0/interaction_based_testing.html#_combining_mocking_and_stubbing

It is required to define number of invocation in the same line where mock method is defined

To post an actual answer for those who follow:

    def "Should verify notify was called"() {         given:         Notifier notifier = Mock(Notifier)          when:         notifier.test()         notifier.test()         def result = notifier.test()          then:         3 * notifier.test() >> {             println("Called in mock...")             return "mock"         }         result == "mock"     } 

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data