So after alot of trail and error with a kotlin class i found that the same code in java is testable but not testable with kotlin.
@RunWith(MockitoJUnitRunner.class)
public class TestStuff {
@Mock
B b;
@Test
public void testStuff(){
A a = new A(b);
Mockito.when(b.provideValue()).thenReturn("");
a.doStuff();
}
}
class A(val b: B) {
fun doStuff() {
b.provideValue()
}
}
open class B {
fun provideValue(): String {
return "b"
}
}
This causes: org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles);
But if i write class B as a java class i.e.
public class B {
public String provideValue(){
return "b";
}
}
The test works. Can some one explain why this is happening or how am i suposed to test kotlin code when mockito does not work consistently.