Mocking case classes with primitive types

一个人想着一个人 提交于 2019-12-04 08:21:21

Here is my test class:

import org.mockito.Mockito._
import org.scalatest.mockito.MockitoSugar
import org.scalatest.FlatSpec

class StackOverflowTest extends FlatSpec with MockitoSugar {

  "Bla" should
    "fsg ll ll" in {
      val entityMock = mock[Entity]
      when(entityMock.id).thenReturn(0)
      foo(entityMock)
    }

  def foo(entity: Entity) = {
    entity.id == 0
  }

}

trait HasId[T] {
  def id: T
}

case class Entity(id: Long) extends HasId[Long]

Here is my sbt file:

name := "scalaExperiments"

version := "0.1"

scalaVersion := "2.12.4"

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % Test

libraryDependencies += "org.mockito" % "mockito-all" % "2.0.2-beta" % Test

Compiles and passes successfully.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!