kotlinfixture icon indicating copy to clipboard operation
kotlinfixture copied to clipboard

Customizing property with private/protected setter

Open djkeh opened this issue 1 year ago • 1 comments

Consider we have a class to create a fixture like this:

class MyClass {
    var name: String = "initial value"
        protected set
}

when we do:

kotlinFixture {
    property(MyClass::name) { "test" }
}

will throw an exception like this:

java.lang.UnsupportedOperationException: Unable to handle MyClass
Unable to resolve class MyClass
    Unable to populate class MyClass
    Unable to instantiate class MyClass using factory methods

    at com.appmattus.kotlinfixture.Fixture.create(KotlinFixture.kt:85)

because the proeprty name doesn't provide public setter. How do I customize that field?

djkeh avatar Apr 25 '23 08:04 djkeh