https://kotlinlang.org logo
Title
m

mplacona

04/04/2018, 2:04 PM
Hey all, quick question as I can't find any solid resources for this. How does one test extension methods? Say I have something like
fun Date.isWeekend() = day == 6 || day == 7
Inside a class. How do I go about unit testing this?
a

andyb

04/04/2018, 2:15 PM
Should be straightforward if you are writing Kotlin Test classes but if you are using Java you can add @JvmName("isWeekend") annotation to the method and then call it by passing the Date as the 1st parameter: e.g.
isWeekend( new Date())
(forgotten how much I hate writting
new
🙂 )
k

kingsley

04/07/2018, 8:11 AM
The JvmName is already
isWeekend
. You shouldn’t need an extra annotation