Mockito.mock fails with BlockHound
Mert-Z opened this issue · comments
Mockito.mock
fails when blockhound-junit-platform
is added to project dependencies.
Expected Behavior
Removing blockhound-junit-platform
from dependencies makes the tests pass. I'd expect tests to pass with BlockHound.
Actual Behavior
[ERROR] testSomeScenario Time elapsed: 0.001 s <<< ERROR!
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
at SomeServiceUTest.testSomeScenario(SomeServiceUTest.java:32)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration@b90c5a5
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.)
Java : 1.8
JVM vendor name : AdoptOpenJDK
JVM vendor version : 25.242-b08
JVM name : OpenJDK 64-Bit Server VM
JVM version : 1.8.0_242-b08
JVM info : mixed mode
OS name : Mac OS X
OS version : 10.14.6
Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@30c03473
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.UnsatisfiedLinkError: Native Library /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib/libattach.dylib already loaded in another classloader
Steps to Reproduce
@Test
public void testSomeScenario() {
mock(Object.class);
}
Possible Solution
Looks like Byte Buddy
dependency pulled transitively by mockito-core
doesn't play nicely with the shaded copy of Byte Buddy
included in BlockHound
library.
+- org.mockito:mockito-core:jar:3.3.3:test
| +- net.bytebuddy:byte-buddy:jar:1.10.14:test
| +- net.bytebuddy:byte-buddy-agent:jar:1.10.14:test
| \- org.objenesis:objenesis:jar:2.6:test
Your Environment
io.projectreactor.tools:blockhound-junit-platform:jar:1.0.4.RELEASE
org.mockito:mockito-core:jar:3.3.3
(viaorg.springframework.boot:spring-boot-starter-test:jar:2.3.4.RELEASE
)org.springframework.boot:spring-boot-starter-reactor-netty:jar:2.3.4.RELEASE
(viaorg.springframework.boot:spring-boot-starter-webflux:jar:2.3.4.RELEASE
)io.projectreactor:reactor-test:jar:3.3.10.RELEASE
- 1.8.0_242-b08 OpenJDK 64-Bit Server VM
- Mac OS X 10.14.6
@bsideup any chance releasing a BlockHound
version without shaded Byte Buddy
included in it?
@bsideup any chance releasing a
BlockHound
version without shadedByte Buddy
included in it?
ah sorry ignore me.. just seen this #70 (comment)
@bsideup any chance releasing a
BlockHound
version without shadedByte Buddy
included in it?ah sorry ignore me.. just seen this #70 (comment)
as a side note, adding JNA to classpath made no difference.
as a side note, adding JNA to classpath made no difference.
This is weird. Adding JNA makes ByteBuddy prefer the emulated attachment strategy, and it should work fine. Since Mockito is maintained by the same person who created ByteBuddy, I would say reporting the issue to them would be the best play. The reproducer can be simplified to:
BlockHound.install()
Mockito.mock(Object.class)
no need to use the junit jupiter integration actually