diff --git a/fixture/src/main/kotlin/com/appmattus/kotlinfixture/config/ConfigurationBuilder.kt b/fixture/src/main/kotlin/com/appmattus/kotlinfixture/config/ConfigurationBuilder.kt index 8db36fea..565da554 100644 --- a/fixture/src/main/kotlin/com/appmattus/kotlinfixture/config/ConfigurationBuilder.kt +++ b/fixture/src/main/kotlin/com/appmattus/kotlinfixture/config/ConfigurationBuilder.kt @@ -583,6 +583,9 @@ class ConfigurationBuilder(configuration: Configuration = Configuration()) { return property(T::class, property.name, generator as GeneratorFun) } + @JvmName("propertyByInfixFunction") + inline infix fun KProperty1.property(noinline generator: Generator.() -> G) = property(this, generator) + /** * Customising generation of class properties with property * diff --git a/fixture/src/test/kotlin/com/appmattus/kotlinfixture/config/ConfigurationBuilderTest.kt b/fixture/src/test/kotlin/com/appmattus/kotlinfixture/config/ConfigurationBuilderTest.kt index e576adf5..470b5b74 100644 --- a/fixture/src/test/kotlin/com/appmattus/kotlinfixture/config/ConfigurationBuilderTest.kt +++ b/fixture/src/test/kotlin/com/appmattus/kotlinfixture/config/ConfigurationBuilderTest.kt @@ -112,6 +112,25 @@ class ConfigurationBuilderTest { } } + @Test + fun `can override properties using property infix function`() { + val original: Generator.() -> Properties = { Properties("2") } + + @Suppress("UNCHECKED_CAST") + val configuration = ConfigurationBuilder( + Configuration(properties = mapOf(Properties::class to mapOf("property" to original as GeneratorFun))) + ).apply { + Properties::property property { "1" } + }.build() + + with(TestGenerator) { + assertEquals( + "1", + (configuration.properties.getValue(Properties::class).getValue("property"))() + ) + } + } + @Test fun `properties is immutable`() { val configuration = ConfigurationBuilder(Configuration()).build()