in the doc of scalamock, it is said that:
mocking classes, traits and case classes
is one of the feature supported.
I have the following case class:
case class Thing(private val item: Item)
When i do:
val item = mock[Thing]
I get the following error:
Error:(18, 24) not enough arguments for constructor Thing: (item: org.dspace.content.Item)org.iadb.poolpartyconnector.dspaceutils.Thing. Unspecified value parameter item. val item = mock[Thing] ^
I know i could implement an interface for it, but in any case, this would help me better understand how to mock a case class/a class that has constructor.
Many thanks,
Maatari
Currently, you cannot mock classes that do not have a default constructor defined.
You can workaround it by creating a subclass that has default constructor defined and mocking that subclass:
class MockableThing extends Thing(null)
val item = mock[MockableThing]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With