0

I am trying to figure out the following:

I have a mocked method, inside this mocked class there is a function with parameter of a function that takes nothing and void return, something like this What does ".()" mean in Kotlin?

fun invokeStuff(values: (MyParametersBuilder.() -> Unit)) {
        // do something and extract values
    }

MyParametersBuilder class has some setters for its own properties.

so when I invoke it I do this

MyClass().invokeStuff{
     setEnableFlagA(true)
}

So now using Mockito I came to this problem where I cannot mock the result of invokeStuff since I have no idea how to do it or if its even possible.

Basically, I cannot do this:

when(myClass.invokeStuff(any(MyParametersBuilder)).thenReturn... <- it says this method doesn't exist

neither

when(myClass.invokeStuff{any(Boolean::class.java)}.thenReturn... <- compiles but doesnt match anything

nor

when(myClass.invokeStuff{}.thenReturn... <- doesn't match either

Any idea how could I do this? Im using kotlin and mockito.

AlexT
  • 2,524
  • 1
  • 11
  • 23
jpganz18
  • 5,508
  • 17
  • 66
  • 115

0 Answers0