Hi,
I have a problem testing a Kotlin enum class from a Groovy test based on Spock Framework: As it seems the enum values from a data pipe (here: data table) are perceived as classes.
I was able to drill down the problem with the attached files. The ZIP contains:
- KAngleUnit - the Kotlin Enum AngleUnit with property symbol and method convert
- JAngleUnit - the same Enum as Java Version
- JUseAngleUnit - an executable class which accesses both the Kotlin and the Java enum
- GUseAngleUnit - an executable groovy class which accesses both the Kotlin and the Java enum
JUseAngleUnit runs without errors. GUseAngleUnit fails with:
Java: DEGREE <class JAngleUnit$1>
Kotlin: class KAngleUnit$DEGREE <class java.lang.Class>
0.0
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method:
static KAngleUnit$DEGREE.convert() is applicable for argument types:
(java.lang.Double, java.lang.Class) values: [0.0, class KAngleUnit$RADIANT]
The first two lines output the enum value and the result of getClass(). As you can see the Java Enum Value has an anonymous class whereas the Kotlin Enum Value is perceived as Class.
Is this an issue? (I think: yes) And if: Is this is a known issue and does a workaround exist?
kotlin-enum-poc.zip (1,7 KB)