Class ByteBuddyCrossClassLoaderSerializationSupport

java.lang.Object
org.mockito.internal.creation.bytebuddy.ByteBuddyCrossClassLoaderSerializationSupport
All Implemented Interfaces:
Serializable

@Incubating class ByteBuddyCrossClassLoaderSerializationSupport extends Object implements Serializable
This is responsible for serializing a mock, it is enabled if the mock is implementing Serializable.

The way it works is to enable serialization with mode SerializableMode.ACROSS_CLASSLOADERS, if the mock settings is set to be serializable the mock engine will implement the ByteBuddyCrossClassLoaderSerializationSupport.CrossClassLoaderSerializableMock marker interface. This interface defines a the ByteBuddyCrossClassLoaderSerializationSupport.CrossClassLoaderSerializableMock.writeReplace() whose signature match the one that is looked by the standard Java serialization.

Then in the proxy class there will be a generated writeReplace that will delegate to MockMethodInterceptor.ForWriteReplace.doWriteReplace(MockAccess) of mockito, and in turn will delegate to the custom implementation of this class writeReplace(Object). This method has a specific knowledge on how to serialize a mockito mock that is based on ByteBuddy and will ignore other Mockito MockMakers.

Only one instance per mock! See MockMethodInterceptor

TODO check the class is mockable in the deserialization side
Since:
1.10.0
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • MOCKITO_PROXY_MARKER

      private static final String MOCKITO_PROXY_MARKER
      See Also:
    • instanceLocalCurrentlySerializingFlag

      private boolean instanceLocalCurrentlySerializingFlag
    • mutex

      private final Lock mutex
  • Constructor Details

    • ByteBuddyCrossClassLoaderSerializationSupport

      ByteBuddyCrossClassLoaderSerializationSupport()
  • Method Details