I am testing a service that has an autowired helper component. That component has autowired repo.
In my test, I want to use that component helper, not a mock. And I want to mock the repo for that.
But I can't manage to make it work.
The Service that I test:
@Service
public class ServiceImpl{
@Autowired
private Helper helper;
}
The Helper class that has autowired repo
@Component
public class Helper {
@Autowired
private Repository repo;
}
My test should be like this
@ExtendWith(MockitoExtension.class)
public class ServiceImplTest {
ServiceImpl service;
@Mock
private Repository repoMock;
@InjectMocks
private Helper helper;
}
I'd like better to refactor the whole thing but unfortunately, it's not possible...
Any help welcome.