Package spock.mock

Class MockMakers

java.lang.Object
spock.mock.MockMakers

public final class MockMakers extends Object
Provides constants and factory methods for known built-in IMockMaker implementations.

You can select the mock maker during mock creation: YourClass yourMock = Mock(mockMaker: MockMakers.byteBuddy)

Since:
2.4
  • Field Details

    • byteBuddy

      public static final IMockMakerSettings byteBuddy
      Uses Byte Buddy to create mocks.

      The supported mocking features are:

      • INTERFACE
      • CLASS
      • ADDITIONAL_INTERFACES
      • EXPLICIT_CONSTRUCTOR_ARGUMENTS
    • cglib

      public static final IMockMakerSettings cglib
      Uses CGLIB to create mocks.

      The supported mocking features are:

      • INTERFACE
      • CLASS
      • ADDITIONAL_INTERFACES
      • EXPLICIT_CONSTRUCTOR_ARGUMENTS
    • javaProxy

      public static final IMockMakerSettings javaProxy
      Uses the Java Proxy API to create mocks of interfaces.

      The supported mocking features are:

      • INTERFACE
      • ADDITIONAL_INTERFACES
    • mockito

      public static final IMockMakerSettings mockito
      Uses Mockito to create mocks, which also supports final classes, enums and final methods.

      The supported mocking features are:

      • INTERFACE
      • CLASS
      • ADDITIONAL_INTERFACES
      • EXPLICIT_CONSTRUCTOR_ARGUMENTS
      • FINAL_CLASS
      • FINAL_METHOD
      • It uses MockMakers.INLINE under the hood, please see the Mockito manual for all pros and cons, when using MockMakers.INLINE.

  • Method Details

    • mockito

      public static IMockMakerSettings mockito(@DelegatesTo(type="org.mockito.MockSettings",strategy=1) Closure<?> settingsCode)
      Uses Mockito to create mocks, which also supports final classes, enums and final methods.

      The supported mocking features are:

      • INTERFACE
      • CLASS
      • ADDITIONAL_INTERFACES
      • EXPLICIT_CONSTRUCTOR_ARGUMENTS
      • FINAL_CLASS
      • FINAL_METHOD
      • It uses MockMakers.INLINE under the hood, please see the Mockito manual for all pros and cons, when using MockMakers.INLINE.

      Parameters:
      settingsCode - the code to execute to configure MockSettings for further configuration of the mock to create