Search code examples
scalaunit-testingscalamock

Scala mock polymorphic methods with implicit type tag


How to mock a polymorphic method with an implicit type tag parameter

val mockInterface = mock[SampleInterface]

trait SampleInterface {

  def fetchType[M <: Model : TypeTag]: Future[Unit]
}

Solution

  • (mockInterface.fetchType[SampleModel](_: TypeTag[SampleModel]))
        .expects(typeTag[SampleMode])
        .returning(Future.successful())