title: Kotlin - Mockito verify method calls
body: <p>I'm trying my hand with Mockito for writing unit test's. I have a class that needs to be tested like below-</p>
  
  <pre><code>open class Employee {
    fun setDetails(name: String, age: Int) {
      setName(name)
      setAge(age)
    }
  
    fun setName(name: String) { }
  
    fun setAge(age: Int) { }
  }
  </code></pre>
  
  <p>Below is my test class</p>
  
  <pre><code>class EmployeeTest {
    @Mock
    lateinit var emp: Employee
  
    @Before
    fun setup() {
      MockitoAnnotations.initMocks(this)
    }
  
    @Test
    fun testDetail() {
      emp.setDetails("Henry", 23)
  
      verify(emp, times(1)).setAge(23)
    }
  
  }
  </code></pre>
  
  <p>Here is my problem</p>
  
  <p>When I do -</p>
  
  <pre><code>verify(emp, times(1)).setAge(23)
  </code></pre>
  
  <p>This give's me a success, because setAge is called once in setDetails() of Employee.kt. So that works fine for me</p>
  
  <p>But, when I do- </p>
  
  <pre><code>verify(emp, never()).setAge(23)
  </code></pre>
  
  <p>This still gives me a success, even though the method is called in setDetails(). Shouldn't this test case fail?</p>
  
  <p>Please help me understand this. I haven't been able to figure out why this happens.</p>
  
  <p><strong>EDIT</strong>
  Here's what worked for me
  I used a spy instead of a mock. However, I had to also declare the methods as open in Kotlin.</p>