Andrea Giuliano
Andrea Giuliano

Reputation: 378

Cucumber parameter type with kotlin

I wonder, is there any example of implementing parameter type with Cucumber in Kotlin?

I've read the official doc but it doesn't explain how to wire it up.

I was looking around but haven't found anything really meaningful.

Any help with this?

Upvotes: 1

Views: 416

Answers (1)

Andrea Giuliano
Andrea Giuliano

Reputation: 378

I found the solution to this. It seems that by just adding a class in the plug package all works

class NumberParameterTypeConfigurer : TypeRegistryConfigurer {
override fun locale(): Locale {
    return Locale.ENGLISH
}

override fun configureTypeRegistry(typeRegistry: TypeRegistry?) {
    typeRegistry?.defineParameterType(ParameterType(
            "number",
            """\b(no|\d)\b""",
            Int::class.java,
            Transformer {
                when (it) {
                    "no" -> 0
                    else -> it.toInt()
                }
            }
    ))
}

}

hope this can help somebody else

Upvotes: 1

Related Questions