kosi-libs / MocKMP

A mocking processor for Kotlin Multiplatform
https://kosi-libs.org/mockmp
MIT License
189 stars 12 forks source link

Cannot access '<init>': it is private in <ClassName> #11

Closed mathieudebrito closed 2 years ago

mathieudebrito commented 2 years ago

Dear MocKMP team,

I just came by your library, and it's pretty awesome ! I ran into a breaking issue using the library : when the data class constructor is private, the following issue is raised : Cannot access '<init>': it is private in <ClassName>

I have a data class like this :

data class Model (
val someInstant: kotlinx.datetime.Instant 
) 

When trying to use in tests :

@UsesFakes(Model::class)
class ModelTests : TestsWithMocks(){
    override fun setUpMocks() = injectMocks(mocker)

    @Fake
    lateinit var model: Model

   ...
}

It generates something like this :

internal fun fakeInstant() = Instant()

The problem is that Instant has private constructor.

Is there any way to add a default way to create fakes ?

Thank you !

SalomonBrys commented 2 years ago

Fixed in 1.4.0.

See https://github.com/Kodein-Framework/MocKMP#providing-fake-instances