-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: testIssues in the test moduleIssues in the test moduletype: enhancementA general enhancementA general enhancement
Milestone
Description
@Qualifier support was recently added for @TestBean, MockitoBean, and MockitoSpyBean fields; however, when the name of the annotated field exactly matches the name of the bean being overridden or spied the field name is not currently used as a fallback qualifier, in contrast to regular injection points (such as @Autowired fields).
For example, the following currently only passes with the presence of @Qualifier("exampleService").
@SpringJUnitConfig
class MockitoBeanFallbackQualifierTests {
@Qualifier("exampleService")
@MockitoBean
ExampleService exampleService;
@Test
void test() {
when(exampleService.greeting()).thenReturn("test");
assertThat(exampleService.greeting()).isEqualTo("test");
}
@Configuration
static class Config {
@Bean
ExampleService exampleService() {
return () -> "prod";
}
@Bean
ExampleService exampleService2() {
return () -> "prod2";
}
}
interface ExampleService {
String greeting();
}
}Whereas, ideally we should be able to remove @Qualifier("exampleService") and have the field name ("exampleService") be used as the fallback qualifier.
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test moduletype: enhancementA general enhancementA general enhancement