I'd like to stub one of the methods of a scala class with dependencies. Is there a way to achieve this using ScalaMock?
Here is a simplified example of what I have:
class TeamService(val dep1: D1) {
def method1(param: Int) = param * dep1.magicNumber()
def method2(param: Int) = {
method1(param) * 2
}
}
In this example I'd like to mock method1()
. My test would look like:
val teamService = ??? // creates a stub
(teamService.method1 _).when(33).returns(22)
teamService.method2(33).should be(44)
Is there a way to achieve this?
method1
and onD1
. Maybe there is not enough information but you maybe should mock all methods you need to use. – Tavey