【发布时间】:2019-10-04 11:41:35
【问题描述】:
如何存根在实现中使用ClassTag 的方法?
class RefsFactory {
def get[I <: Item : ClassTag]: RefTo[I] = {
val itemType = implicitly[ClassTag[A]].runtimeClass.asInstanceOf[Class[A]]
// ...
}
}
这个类在我们的代码中被大量使用,我想将它存根以返回其他关于 itemType 的模拟。
val factory = stub[RefsFactory]
val otherType = stub[RefTo[OtherType]]
(factory.get[OneType]) returns RefTo(new OneType())
(factory.get[OtherType]) returns otherType
谢谢
【问题讨论】:
标签: scala testing stub stubbing scalamock