I’ve been using Mockito for quite a long time now and I consider myself rather fluent at that. Mock verification is not a case that I use often, but I can imagine a case for that. In Mockito I would just write a test like this one:
I’m just checking the result and verifying the call of the mock.
I recently wanted to do something similar in Spock, a fresh-and-all-blinky-test-framework. So, I wrote:
First run, aaaaaand it failed. I thought that the problem was with my mocking the final class, which URL is, but I also tried mocking a non-final class with same effect. After some time I found the answer in the Spock docs.
This is the correct version:
TL;DR: Stubbing and mocking in Spock example here.