I have service classes ClassA and ClassB, both implementing the same interface with a generic parameter.
@Service
@Qualifier(value = "CountryService")
public class CountryService implements SupportCoreService<Country> {}
@Service
@Qualifier(value = "UniversityService")
public class UniversityService implements SupportCoreService<University> {}
I have their common methods implemented, they are injected with the @Qualifier annotation and have no issues. However, Mockito seems not to respect this annotation, and practically ignores one of the mocks and tries to call the same method twice and thus fail my tests.
This is my test setup:
@ExtendWith(MockitoExtension.class)
class StudentApplicationServiceTest {
@Mock
@Qualifier("CountryService")
SupportCoreService<Country> countrySupportCoreService;
@Mock
@Qualifier("UniversityService")
SupportCoreService<University> universitySupportCoreService;
@InjectMocks
StudentApplicationService underTest;
}
There are no compile errors of any sort, when I run the tests the error message says that “Wanted but not invoked:” as the other method gets called twice.
I have looked through dozens of SO topics and other Google search results, refactored the setup dozen+ times but nothing seems to help. Any help to put me on track?