How to mock a class with scala mock

in the dock of Skalamok, they say that:

mocking classes, traits and case classes

is one of the supported features.

I have the following case class:

case class DspaceItemWrapper(private val item: Item)

When i do:

val item = mock[DspaceItemWrapper]

I get the following error:

Error: (18, 24) there are not enough arguments for the DspaceItemWrapper constructor: (item: org.dspace.content.Item) org.iadb.poolpartyconnector.dspaceutils.DspaceItemWrapper. Optional parameter parameter value. val item = mock [DspaceItemWrapper] ^

I know that I can implement an interface for it, but in any case it will help me better understand how to mock the case / class class, which has a constructor.

Many thanks,

Maatari

+4
source share
1 answer

, .

, , :

class MockableDspaceItemWrapper extends DspaceItemWrapper(null)
val item = mock[MockableDspaceItemWrapper]
+11

All Articles