I want to write a unit test for my controller which uses multiple services inside it. How can I use multiple mockFor() for services? Tnx.
For example using spock for testing:
class ExampleControllerUnitSpec extends Specification {
def anyService
def anotherService
def setup() {
anyService = Mock(AnyService)
controller.anyService = anyService
anotherService = Mock(AnotherService)
controller.anotherService = anotherService
}
def "test"(){
when:
controller.action()
then:
1 * anyService.doSomething() >> "result"
3 * anotherService.doSomethingElse() >> "result2"
}
}