title: How to mock and verify Lambda expression in Kotlin?
body: <p>In Kotlin (and Java 8) we can use Lambda expression to remove boilerplate callback interface. For example,</p>
  
  <pre><code>data class Profile(val name: String)
  
  interface ProfileCallback {
    fun onSuccess(profile: Profile)
  }
  
  class ProfileRepository(val callback: ProfileCallback) {
  
    fun getProfile() {
      // do calculation
      callback.onSuccess(Profile("name"))
    }
  }
  </code></pre>
  
  <p>We can change remove <code>ProfileCallback</code> and change it into Kotlin's Lambda:</p>
  
  <pre><code>class ProfileRepository(val callback: (Profile) -&gt; Unit) {
  
    fun getProfile() {
      // do calculation
      callback(Profile("name"))
    }
  }
  </code></pre>
  
  <p>This works fine, but I'm not sure how to mock and then verify that function. I have
  tried using Mockito like this</p>
  
  <pre><code>@Mock
  lateinit var profileCallback: (Profile) -&gt; Unit
  
  @Test
  fun test() {
      // this wouldn't work
      Mockito.verify(profileCallback).invoke(any())   
  }
  </code></pre>
  
  <p>but it throw an Exception:</p>
  
  <blockquote>
    <p>org.mockito.exceptions.base.MockitoException:  ClassCastException
    occurred while creating the mockito mock :   class to mock :
    'kotlin.jvm.functions.Function1', loaded by classloader :
    'sun.misc.Launcher$AppClassLoader@7852e922'</p>
  </blockquote>
  
  <p>How to mock and verify Lambda expression in Kotlin? Is it even possible?</p>