2
class MyClassWithVals(val a: String, val b: String, val c: String) {}

Can I mock this with ScalaMock in some such that:

val mock = stub[MyClassWithVals]
//when mock.a expect "The value of a"

The reason I want to mock this, rather than just creating an instance of MyClassWithVals with values filled in is that I have a class with 10 or more parameters and I only want to define the behaviour of one or two of them for tests.

If not with ScalaMock, is there another library where it's straightforward, or is there a limitation of what can be done with the Scala class vals?

David B
  • 455
  • 6
  • 13

1 Answers1

0

I've worked around by creating another test-only class which extends MyClassWithVals:

class MyClassWithValsStub(
  override val a: String = null,
  override val b: String = null,
  override val c: String = null
) extends MyClassWithVals(
  a,
  b,
  c
) {}

Using this additional class, I can say in my test cases:

var myStub = new MyClassWithValsStub(b = "Test B")
David B
  • 455
  • 6
  • 13