0

I have a problem when active mockito inline. The test works perfectly in normal mode. The error is:

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 25.556 s <<< FAILURE! - in es.ddmain.utils.FileSystemUtilsTest
[ERROR] testIntentarSubirImagenYtestBorrarFichero  Time elapsed: 25.548 s  <<< ERROR!
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
        at es.ddmain.utils.FileSystemUtilsTest.testIntentarSubirImagenYtestBorrarFichero(FileSystemUtilsTest.java:61)
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.CompoundEnumeration@249676e4
        at es.ddmain.utils.FileSystemUtilsTest.testIntentarSubirImagenYtestBorrarFichero(FileSystemUtilsTest.java:61)
Caused by: java.lang.reflect.InvocationTargetException
        at es.ddmain.utils.FileSystemUtilsTest.testIntentarSubirImagenYtestBorrarFichero(FileSystemUtilsTest.java:61)
Caused by: org.mockito.exceptions.base.MockitoInitializationException:

Could not initialize inline Byte Buddy mock maker.

It appears as if your JDK does not supply a working agent attachment mechanism.
Java               : 11
JVM vendor name    : Oracle Corporation
JVM vendor version : 11.0.2+9-LTS
JVM name           : Java HotSpot(TM) 64-Bit Server VM
JVM version        : 11.0.2+9-LTS
JVM info           : mixed mode
OS name            : Windows 7
OS version         : 6.1

        at es.ddmain.utils.FileSystemUtilsTest.testIntentarSubirImagenYtestBorrarFichero(FileSystemUtilsTest.java:61)
Caused by: java.lang.IllegalStateException: Could not self-attach to current VM using external process
        at es.ddmain.utils.FileSystemUtilsTest.testIntentarSubirImagenYtestBorrarFichero(FileSystemUtilsTest.java:61)

[EDIT] Sorry, i forgot to include version of mockito.

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-junit-jupiter</artifactId>
    <version>4.8.1</version>
    <scope>test</scope>
</dependency>

what can i do to fix this? I'm noob in mockito

Thanks

Blrackerd
  • 17
  • 7

2 Answers2

1

Most likely you ran across Could not self-attach to current VM using external process (ByteBuddyAgent.installExtension) #2741

Mockito is known not to be able to mock a few classes it uses in its internals. The issue is closed as infeasable

Unfortunately, InputStream is one of the classes that Mockito relies on internally for its behavior. Stubbing InputStream will therefore lead to undefined behavior. Additionally, it is advised not to mock classes you don't own: https://github.com/mockito/mockito/wiki/How-to-write-good-tests#dont-mock-a-type-you-dont-own We are working on improving the user experience by working on a DoNotMock feature to avoid mocking classes/methods that are known to crash Mockito internals (#1833). Therefore, I am closing this as "Infeasible". Apologies for the uninformative exception that is thrown.

Lesiak
  • 22,088
  • 2
  • 41
  • 65
  • Thanks, I understand but this only throw the error if i active "mock-maker-inline" mode, in normal mode works perfectly. Is there a way to run some tests in "mock-maker-inline" mode and others in normal mode? – Blrackerd Apr 03 '23 at 20:34
  • 1
    @Blrackerd If possible, I would look for ways not to mock these problematic classes. For example, instead of mocking InputStream, you can create one from a given String (https://stackoverflow.com/questions/782178/how-do-i-convert-a-string-to-an-inputstream-in-java) etc. – Lesiak Apr 03 '23 at 21:22
-1

i have same problem!!

Caused by: java.lang.IllegalStateException: Internal problem occurred, please report it. Mockito is unable to load the default implementation of class that is a part of Mockito distribution. Failed to load interface org.mockito.plugins.MockMaker
    at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.create(DefaultMockitoPlugins.java:104)
    at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.getDefaultPlugin(DefaultMockitoPlugins.java:78)
    at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:75)
    at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:50)
    at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:27)
    at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:22)
    at org.mockito.internal.MockitoCore.<clinit>(MockitoCore.java:73)
    at org.mockito.Mockito.<clinit>(Mockito.java:1669)
    at org.springframework.boot.test.mock.mockito.MockReset.withSettings(MockReset.java:81)
    at org.springframework.boot.test.mock.mockito.MockDefinition.createMock(MockDefinition.java:147)
    ... 86 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.create(DefaultMockitoPlugins.java:102)
    ... 95 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException: 
Could not initialize inline Byte Buddy mock maker.

it doesn't work when i choosed orcal17 or amazon17

It appears as if your JDK does not supply a working agent attachment mechanism.
Java               : 17
JVM vendor name    : Amazon.com Inc.
JVM vendor version : 17.0.6+10-LTS
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 17.0.6+10-LTS
JVM info           : mixed mode, sharing
OS name            : Windows 10
OS version         : 10.0
Criss
  • 9
  • 1
  • This does not answer the question. It should've been summarized as a comment under the original post – Narish Apr 17 '23 at 18:03