MockBuilder
Date: 2015-09-17

org.easymock.internal

## Class MockBuilder<T>

- java.lang.Object
- - org.easymock.internal.MockBuilder<T>

- Type Parameters:
    `T` - type of the mock created
  All Implemented Interfaces:
    IMockBuilder<T>

      public class MockBuilder<T>
      extends java.lang.Object
      implements IMockBuilder<T>

  Default implementation of IMockBuilder.

  The original idea and part of the code where contributed by Rodrigo Damazio and Bruno Fonseca at Google

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MockBuilder(java.lang.Class<T> toMock)`
    `MockBuilder(java.lang.Class<T> toMock, EasyMockSupport support)` Used by EasyMockSupport to allow the mock registration in the list of controls

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `IMockBuilder<T>` | `addMockedMethod(java.lang.reflect.Method method)` Adds a method to be mocked in the testing class.
    `IMockBuilder<T>` | `addMockedMethod(java.lang.String methodName)` Adds a method to be mocked in the testing class.
    `IMockBuilder<T>` | `addMockedMethod(java.lang.String methodName, java.lang.Class<?>... parameterTypes)` Adds a method to be mocked in the testing class.
    `IMockBuilder<T>` | `addMockedMethods(java.lang.reflect.Method... methods)` Adds methods to be mocked in the testing class.
    `IMockBuilder<T>` | `addMockedMethods(java.lang.String... methodNames)` Adds methods to be mocked in the testing class.
    `T` | `createMock()` Create a default mock from this builder.
    `T` | `createMock(IMocksControl control)` Create mock from the provided mock control using the arguments passed to the builder.
    `T` | `createMock(MockType type)` Create mock of the request type from this builder.
    `T` | `createMock(java.lang.String name)` Create named mock from the provided mock control using the arguments passed to the builder.
    `T` | `createMock(java.lang.String name, IMocksControl control)` Create named mock from the provided mock control using the arguments passed to the builder.
    `T` | `createMock(java.lang.String name, MockType type)` Create a named mock of the request type from this builder.
    `T` | `createNiceMock()` Create a nice mock from this builder.
    `T` | `createNiceMock(java.lang.String name)` Create a named nice mock from this builder.
    `T` | `createStrictMock()` Create a strict mock from this builder.
    `T` | `createStrictMock(java.lang.String name)` Create a named strict mock from this builder.
    `IMockBuilder<T>` | `withArgs(java.lang.Object... initArgs)` Defines the arguments to be passed to the constructor of the class.
    `IMockBuilder<T>` | `withConstructor()` Defines the empty constructor should be called.
    `IMockBuilder<T>` | `withConstructor(java.lang.Class<?>... argTypes)` Defines the exact argument types for the constructor to use.
    `IMockBuilder<T>` | `withConstructor(java.lang.reflect.Constructor<?> constructor)` Defines the constructor to use to instantiate the mock.
    `IMockBuilder<T>` | `withConstructor(ConstructorArgs constructorArgs)`
    `IMockBuilder<T>` | `withConstructor(java.lang.Object... initArgs)` Defines the constructor parameters for the mocked class.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MockBuilder

          public MockBuilder(java.lang.Class<T> toMock)

    - #### MockBuilder

          public MockBuilder(java.lang.Class<T> toMock,
                     EasyMockSupport support)

      Used by EasyMockSupport to allow the mock registration in the list of controls
      Parameters:
        `toMock` - The class of the mock to create
        `support` - The EasyMockSupport used to create mocks. Null if none

  - ### Method Detail

    - #### addMockedMethod

          public IMockBuilder<T> addMockedMethod(java.lang.reflect.Method method)

      Description copied from interface: `IMockBuilder`
      Adds a method to be mocked in the testing class. Each call will add a new method to the result mock. The method is searched for in the class itself as well as superclasses.
      Specified by:
        `addMockedMethod` in interface `IMockBuilder<T>`
      Parameters:
        `method` - method to be mocked
      Returns:
        this

    - #### addMockedMethod

          public IMockBuilder<T> addMockedMethod(java.lang.String methodName)

      Description copied from interface: `IMockBuilder`
      Adds a method to be mocked in the testing class. Each call will add a new method to the result mock. The method is searched for in the class itself as well as superclasses. There must be no overload of the method. You will have to rely on the other `addMockedMethod`s in this class if that is the case.
      Specified by:
        `addMockedMethod` in interface `IMockBuilder<T>`
      Parameters:
        `methodName` - name of the method to be mocked
      Returns:
        this

    - #### addMockedMethod

          public IMockBuilder<T> addMockedMethod(java.lang.String methodName,
                                        java.lang.Class<?>... parameterTypes)

      Description copied from interface: `IMockBuilder`
      Adds a method to be mocked in the testing class. Each call will add a new method to the result mock. The method is searched for in the class itself as well as superclasses.
      Specified by:
        `addMockedMethod` in interface `IMockBuilder<T>`
      Parameters:
        `methodName` - name of the method to be mocked
        `parameterTypes` - types of the parameters of the method
      Returns:
        this

    - #### addMockedMethods

          public IMockBuilder<T> addMockedMethods(java.lang.String... methodNames)

      Description copied from interface: `IMockBuilder`
      Adds methods to be mocked in the testing class. Same as `IMockBuilder.addMockedMethod(String)` but to mock many methods at once.
      Specified by:
        `addMockedMethods` in interface `IMockBuilder<T>`
      Parameters:
        `methodNames` - names of the methods to be mocked
      Returns:
        this

    - #### addMockedMethods

          public IMockBuilder<T> addMockedMethods(java.lang.reflect.Method... methods)

      Description copied from interface: `IMockBuilder`
      Adds methods to be mocked in the testing class. Same as `IMockBuilder.addMockedMethod(Method)` but to mock many methods at once.
      Specified by:
        `addMockedMethods` in interface `IMockBuilder<T>`
      Parameters:
        `methods` - methods to be mocked
      Returns:
        this

    - #### withConstructor

          public IMockBuilder<T> withConstructor(java.lang.reflect.Constructor<?> constructor)

      Description copied from interface: `IMockBuilder`
      Defines the constructor to use to instantiate the mock. It is expected that you call `IMockBuilder.withArgs(java.lang.Object...)` with the actual constructor argument values after this.
      Specified by:
        `withConstructor` in interface `IMockBuilder<T>`
      Parameters:
        `constructor` - the constructor to be called
      Returns:
        this

    - #### withConstructor

          public IMockBuilder<T> withConstructor(ConstructorArgs constructorArgs)

    - #### withConstructor

          public IMockBuilder<T> withConstructor()

      Description copied from interface: `IMockBuilder`
      Defines the empty constructor should be called.
      Specified by:
        `withConstructor` in interface `IMockBuilder<T>`
      Returns:
        this

    - #### withConstructor

          public IMockBuilder<T> withConstructor(java.lang.Object... initArgs)

      Description copied from interface: `IMockBuilder`
      Defines the constructor parameters for the mocked class. The builder will automatically find a constructor with compatible argument types. This throws an exception if there is more than one constructor which would accept the given parameters.
      Specified by:
        `withConstructor` in interface `IMockBuilder<T>`
      Parameters:
        `initArgs` - arguments of the constructor
      Returns:
        this

    - #### withConstructor

          public IMockBuilder<T> withConstructor(java.lang.Class<?>... argTypes)

      Description copied from interface: `IMockBuilder`
      Defines the exact argument types for the constructor to use. It is expected that you call `IMockBuilder.withArgs(java.lang.Object...)` with the actual constructor argument values after this.
      Specified by:
        `withConstructor` in interface `IMockBuilder<T>`
      Parameters:
        `argTypes` - the exact argument types of the constructor
      Returns:
        this

    - #### withArgs

          public IMockBuilder<T> withArgs(java.lang.Object... initArgs)

      Description copied from interface: `IMockBuilder`
      Defines the arguments to be passed to the constructor of the class. The types of the arguments must match those previously defined with `IMockBuilder.withConstructor(Class...)` or `IMockBuilder.withConstructor(Constructor)`.
      Specified by:
        `withArgs` in interface `IMockBuilder<T>`
      Parameters:
        `initArgs` - the arguments to pass to the constructor
      Returns:
        this

    - #### createMock

          public T createMock(MockType type)

      Description copied from interface: `IMockBuilder`
      Create mock of the request type from this builder. The same builder can be called to create multiple mocks.
      Specified by:
        `createMock` in interface `IMockBuilder<T>`
      Parameters:
        `type` - the mock type
      Returns:
        the newly created mock

    - #### createMock

          public T createMock(java.lang.String name,
                     MockType type)

      Description copied from interface: `IMockBuilder`
      Create a named mock of the request type from this builder. The same builder can be called to create multiple mocks.
      Specified by:
        `createMock` in interface `IMockBuilder<T>`
      Parameters:
        `name` - the mock name
        `type` - the mock type
      Returns:
        the newly created mock

    - #### createMock

          public T createMock(IMocksControl control)

      Description copied from interface: `IMockBuilder`
      Create mock from the provided mock control using the arguments passed to the builder.
      Specified by:
        `createMock` in interface `IMockBuilder<T>`
      Parameters:
        `control` - `IMocksControl` used to create the object
      Returns:
        the newly created mock

    - #### createMock

          public T createMock()

      Description copied from interface: `IMockBuilder`
      Create a default mock from this builder. The same builder can be called to create multiple mocks.
      Specified by:
        `createMock` in interface `IMockBuilder<T>`
      Returns:
        the newly created mock

    - #### createNiceMock

          public T createNiceMock()

      Description copied from interface: `IMockBuilder`
      Create a nice mock from this builder. The same builder can be called to create multiple mocks.
      Specified by:
        `createNiceMock` in interface `IMockBuilder<T>`
      Returns:
        the newly created mock

    - #### createStrictMock

          public T createStrictMock()

      Description copied from interface: `IMockBuilder`
      Create a strict mock from this builder. The same builder can be called to create multiple mocks.
      Specified by:
        `createStrictMock` in interface `IMockBuilder<T>`
      Returns:
        the newly created mock

    - #### createMock

          public T createMock(java.lang.String name,
                     IMocksControl control)

      Description copied from interface: `IMockBuilder`
      Create named mock from the provided mock control using the arguments passed to the builder.
      Specified by:
        `createMock` in interface `IMockBuilder<T>`
      Parameters:
        `name` - the mock name
        `control` - `IMocksControl` used to create the object
      Returns:
        the newly created mock

    - #### createMock

          public T createMock(java.lang.String name)

      Description copied from interface: `IMockBuilder`
      Create named mock from the provided mock control using the arguments passed to the builder.
      Specified by:
        `createMock` in interface `IMockBuilder<T>`
      Parameters:
        `name` - the mock name
      Returns:
        the newly created mock

    - #### createNiceMock

          public T createNiceMock(java.lang.String name)

      Description copied from interface: `IMockBuilder`
      Create a named nice mock from this builder. The same builder can be called to create multiple mocks.
      Specified by:
        `createNiceMock` in interface `IMockBuilder<T>`
      Parameters:
        `name` - the mock name
      Returns:
        the newly created mock

    - #### createStrictMock

          public T createStrictMock(java.lang.String name)

      Description copied from interface: `IMockBuilder`
      Create a named strict mock from this builder. The same builder can be called to create multiple mocks.
      Specified by:
        `createStrictMock` in interface `IMockBuilder<T>`
      Parameters:
        `name` - the mock name
      Returns:
        the newly created mock