私がこれを持っているとしましょう:
class Dependency1 {
def methodD1 { }
}
class Dependency2 {
val dependency1 = new Dependency1
}
def myMethod() {
val a = new Dependency1
// I want to be able to stub this
val b = a.dependency1.methodD1()
...
}
RR(ルビーモックライブラリ)のようなことをしたい:
any_instance_of(Dependency1) do | obj |
stub(obj) { "123" } # this would be like stub(obj) toReturn("123") with Mockito in Scala
end
Mockito には any メソッドがあることは知っていますが、それはマッチャーです。私は次のようなものを探しています:
stub(anyInstanceOf(Dependency1).methodD1) toReturn("123")
Mockito/EasyMock/PowerMock/JMock でローカル依存関係をモック/スタブする方法はありますか?
私は MockitoSugar で ScalaTest を使用しています。