I am having a simple controller class
@RestController
open class MyController() {
@Autowired
lateinit var myInterface: MyInterface
@GetMapping(value = ["/v1/call-Api"], produces = ["application/json"])
fun getData():Response{
callFx()
/// Here I have logic
}
fun callFx():String{
return myInterface.getmyStringData()
}
}
Now Come to implementation part of
MyInterface
@Service
class MyImpl: MyInterface {
override fun getmyStringData(){
return "Some string"
}
}
Please note that for MyInterface, I have only one implementation class.
Now come to Test case of controller class
class ControllerTest{
@Autowired
lateinit var myIntF: Myinterface
@Test
fun controllerTest(){
Mockito.`when`(myIntF.getmyStringData()).thenReturn("Some mock string")
// Some code over here
}
}
After all these I am keep getting below error
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);
Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
Mocking methods declared on non-public parent classes is not supported.
2. inside when() you don't call method on mock but on some other object.
Even though code syntax belongs to Kotlin but i keep it simple to elaborate me scenario. Any JAVA guy can also help me.
Any help would be really helpful for me.