Closed
Description
Using Spring Boot 3.4.2
Bug Reports
Given the following classes
@Component
public class BaseService {
public void doSomething() {}
}
@Primary
@Component
public class ServiceB extends BaseService {
}
@Component
public class ServiceA {
private final BaseService serviceB;
public ServiceA(BaseService serviceB) {
this.serviceB = serviceB;
}
public void callB() {
serviceB.doSomething();
}
}
The following test works with @MockBean but fails with @MockitoBean because the mocked bean is not injected into ServiceA
@SpringBootTest
class MockitobeanApplicationTests {
@Autowired
ServiceA serviceA;
@MockitoBean
BaseService baseService;
@Test
void contextLoads() {
serviceA.callB();
verify(baseService).doSomething();
}
}
Enhancements requests
This used to/does work with @MockBean