This is just a quick note to self because I am prone to forget such things. This blog is my reminder right? I am writing down the things that may be of use later.
So, today I spent a few hours trying to write just one test. For this chained method call:
We are writing tests in both Groovy and Java, but this one was in Groovy. I was trying to stub the invocation so that it would be used in all the chained calls. And I was failing.
First I tried to use this kind of stub:
So, I declared a stub and I returned it all the time. No luck! Only the first chained method was called.
Then I thought, what if we try to return this instead? Unfortunately, in this case this point to the instance of your test class and not your stub, which I promptly learned.
So, I turned to the best authority.
Google and StackOverflow.
In the end, this is how it worked:
So, the principle is that you have to create another stub for a chained method call, and then they get chained.
I live and I learn.