我想存根具有依赖关系的 scala 类的方法之一。有没有办法使用 ScalaMock 来实现这一点?
这是我所拥有的简化示例:
class TeamService(val dep1: D1) {
def method1(param: Int) = param * dep1.magicNumber()
def method2(param: Int) = {
method1(param) * 2
}
}
在这个例子中,我想模拟method1()
. 我的测试看起来像:
val teamService = ??? // creates a stub
(teamService.method1 _).when(33).returns(22)
teamService.method2(33).should be(44)
有没有办法做到这一点?