Android
Android

Reputation: 150

How to mockk() class with val

class Totals {
    val subTotals = mutableMapOf<String, SubTotals >()
}
data class SubTotals(
    val x: Int = 0, 
    val y: Int = 0
)
every { getTotals() } returns Totals(
      subTotals = mutableMapOf("Bag" to SubTotals(10, 100)))

When I try to mockk() Totals I get cannot find a parameter with this name 'subTotals'

Upvotes: 0

Views: 608

Answers (1)

Nikolai  Shevchenko
Nikolai Shevchenko

Reputation: 7521

You should move subTotals to constructor

From

class Totals {
    val subTotals = mutableMapOf<String, SubTotals>()
}

to

class Totals(
    val subTotals: MutableMap<String, SubTotals> = mutableMapOf()
)

Upvotes: 1

Related Questions