I have an abstract class and a derived class. The derived class is a serivce so is autowired into the test class. Theres a method in the abstract class that I need to mock and test. My current implementation is not working and I'm not sure why.
I've created a spy of the class I want to test and I've called the method using the spy in the test. But still mockito fails to return my mocked value.
abstract class AbstractMyClass {
fun hello(): String {
"bello"
}
}
@Service
class MyClass: AbstractMyClass() {}
My Test stub is
@Autowired
private lateinit var myClass: MyClass
@Test
fun `test hello`() {
val spy = Mockito.spy(myClass)
Mockito.doReturn("cello").`when`(spy).hello()
val res = spy.hello()
Assert.assertEquals("cello", res)
}
What am I doing wrong here?