I'm using scalatest along with scalamock for my small project. I have created a trait and a class, along with its companion object.
trait A{
def getSomething(arg1)
}
class B(field1)....
object B extends A{
def apply(arg1) = new B(getSomething(arg1))
}
The code works great, but the problem occures while testing this code. Unit test should be independend, therefore I should somehow mock/stub trait A:
val fakeA = stub[A]
(fakeA.getSomething _).when(arg).returns(res)
And now... How am I supposed to use this mocked trait in my unit test? Mocking creates an object (not a type) and with code like this I'm unable to "pass it" to my object (or use with). How can I achieve my goal (stub/mock getSomething() inside my B object)? I have tried to split object B into Blogic and B extending Blogic. But what then?
new B(whateverYourMockWouldReturn)
then, and test that. – Dima