'Using scalamock: Could not find implicit value for evidence parameter of type error

I am writing unit tests for my spark/scala application. I am using scalamock as well to mock objects, specifically Session / Session Factory.

In one of my test classes, I try to mock the Session. Ex:

val mockedSession = mock[Session]

However, I get this error:

could not find implicit value for evidence parameter of type
org.scalamock.util.Defaultable[org.hibernate.SimpleNaturalldLoadAccess]

I am getting similar errors no matter the object I mock. The format looks correct.



Solution 1:[1]

From the section "Advanced Topics / Raw Types" in the documentation:

"mocking a java method with raw type" should "work" in {
  implicit val d = new Defaultable[java.util.Enumeration[_]] {
    override val default = null
  }
  implicit val d2 = new Defaultable[java.util.Map[_, _]] {
    override val default = null
  }
  
  val mockedRaw = mock[RawTypeInterface]
}

In my case simply importing the offending type resolved the error.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peewee 733