I've found a strange behavior when using Mockito 5 together with Spring. I'm not sure whether this is a bug in Mockito or in Spring but my corresponding bug report in the Mockito project has been closed with the request to report it here: https://github.com/mockito/mockito/issues/2999
The following test fails due to the timeout as the instantiation of the proxied configuration class seems to stall:
@Test
@Timeout(value = 5, threadMode = SEPARATE_THREAD)
void stallsOnConfigClassInitialization() {
new AnnotationConfigApplicationContext(ProxiedConfigurationClass.class);
}
@Configuration
static class ProxiedConfigurationClass {
static Object object = Mockito.mock(Object.class);
}
If proxyBeanMethods = false
is set on the configuration class, then the test won't stall, and thus succeed.
If the tests are run sequentially, first with proxying and then without proxying, then both tests will time out.
This behavior occurs with both Mockito 5.0.0 and 5.3.1 but not with 4.11.0.
Apart from Mockito, I'm using the following versions:
- OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode, sharing)
- Spring Framework 6.0.8
- JUnit Jupiter 5.9.2
- Gradle 7.6.1
I've pushed a complete reproducer here: https://github.com/hpoettker/mockito-reproducer/blob/main/src/test/java/reproducer/MockitoReproducerTests.java
Comment From: sbrannen
Closing as a duplicate of #27180.
Please ask the Mockito team to reopen https://github.com/mockito/mockito/issues/2999 in order to look into what Mockito can do to support such use cases. Alternatively, perhaps the Mockito team can suggest a workaround.
Comment From: hpoettker
Thanks for the reference to the previous issue! It turns out that my issue at Mockito is also a duplicate of the issue that was created back then: mockito/mockito#2362