https://kotlinlang.org logo
Title
t

tKw

01/08/2019, 1:28 AM
Is it possible to verify code within a lambda is ran? With the following code:
fun getAllActiveWidgetsByPrice(db: DatabaseConnection): List<Widgets> = db.query {
    Widgets.select {
        Widgets.active eq true
    }.orderBy(Widget.price).map { toWidget(it) }
}
Could we verify that
Widgets.select
is called? Could we verify that we pass a lambda with
Widgets.active eq true
to
Widgets.select
? I feel like there is a way to do this, but I have not been able to get it to work.
h

Hadi Tok

01/08/2019, 7:48 AM
I think you can mockStatic Widgets. And run verify on the function. The lambda you are passing is anonymous. So you may not verify it is called. You can use any() in the matcher.