Is it possible to mock an object with Mockito which is called somewhere in the object hierarchy?
Let's assume following classes:
@Component
Class A
@Autowired B b
method obtainSalaryA()
calls b.calculateSalary()
@Component
Class B
@Autowired C c
method calculateSalary()
calls c.getDatabaseSalary()
@Component
Class C
getDatabaseSalary()
In the unit test, I would like to unit test the method obtainSalary
from class A
, but mock C at the same time, so that I replace the return value of getDatabaseSalary()
when this method is called in the hierarchy.