title: How to mock inline function with lambda using Mockito
body: <p>Have a problem with mocking the inline function with lambda. Have class <code>UserController</code>, trying to mock <code>tracer</code> with function <code>createSpan</code>.</p>
  <p>UserController class:</p>
  <pre><code>class UserController(private val tracer:Tracer) {
    fun subscribeUser() {
      tracer.createSpan(&quot;GraphDB: subscribedUser&quot;) {
         do something...
      }
    }
  }
  </code></pre>
  <p><code>createSpan</code> inline function:</p>
  <pre><code>inline fun &lt;T&gt; Tracer.createSpan(operationName: String, block: SpanContext.() -&gt; T): T =
      buildSpan(operationName)
          .start()
          .useOn(this, block)
  </code></pre>
  <p>Tried:</p>
  <pre><code> Mockito.`when`(mockTracer.createSpan&lt;Any&gt;(any(), any())).thenReturn(mockSpanContext)  
  </code></pre>
  <p>returns <code>org.mockito.exceptions.misusing.InvalidUseOfMatchersException</code></p>
  <pre><code> Mockito.`when`(mockTracer.createSpan&lt;SpanContext&gt;(&quot;GraphDB: subscribedUser&quot;, any())).thenReturn(mockSpanContext)
  
  </code></pre>
  <p>returns <code>java.lang.NullPointerException</code></p>
  <p>Tried different approaches but return only <code>org.mockito.exceptions.misusing.InvalidUseOfMatchersException</code> or <code>java.lang.NullPointerException</code>.</p>
  <p>How can I mock this inline function with a lambda or just ignore it, because I don't want to test this function? Any help appreciated.</p>