title: Mocking Interfaces with Kotlin and Mockito
body: <p>I don't really understand interface mocking in Kotlin. I'm not sure if this is Kotlin specific or applies to java also. So far I have only tried it in Kotlin.</p>
  
  <p>I have a mocked class with interfaces:</p>
  
  <pre><code>val mockObj = mock(MyClass::class.java, withSettings().extraInterfaces(IMyInterface::class.java)
  </code></pre>
  
  <p>now, this produces the following problem in IntelliJ:</p>
  
  <pre><code>`when`(mockObj.someMethod()).thenReturn(0.1)
  </code></pre>
  
  <p>the <code>someMethod()</code> will be <em>red</em> (I assume this depends on the color scheme, but you get the idea - a problem: <em>unresolved reference</em>)</p>
  
  <p>to solve this, I simply include this line before it:</p>
  
  <pre><code>val mockInterface = mockObj as IMyInterface
  </code></pre>
  
  <p>the mockInterface will be grey squigly underlined because it is <em>never used</em>. I still use <code>mockObj</code> for the <code>when</code></p>
  
  <p>however, this makes the <em>red</em> disappear</p>
  
  <p>I'm not sure why this works... can someone explain the theory?</p>
  
  <p>to get rid of the grey underline, I then remove <code>val mockInterface =</code></p>
  
  <p>so my magic line is reduced to <code>mockObj as IMyInterface</code></p>