Say I have the following:
@ImplementedBy(classOf[DefaultFoo])
trait Foo {
def a (s : String) : Int
}
class DefaultFoo @Inject()() extends Foo{
override def a (s : String) = 1
}
@ImplementedBy(classOf[DefaultBaz])
trait Baz {
def b (s : String) : Int
}
class DefaultBaz @Inject()(val f :Foo) extends Baz{
override def a (s : String) = 1
}
If I want to test, say DefaultBaz, I am normally using ScalaMock and I would mock as follows in my test spec:
class DefaultBazSpec extends AnyWordSpec with MockFactory{
val mockFoo = mock[Foo]
val b = new DefaultBaz(mockFoo)
// write tests
}
But I could also do this:
val mockFoo = mock[DefaultFoo]
Which one is better? Mock the trait or the default class implementation?