MocksControl (EasyMock 3.2 API)
Date: 2013-07-11

org.easymock.internal

## Class MocksControl

- java.lang.Object
- - org.easymock.internal.MocksControl

- All Implemented Interfaces:
    Serializable, IExpectationSetters<Object>, IMocksControl

      public class MocksControl
      extends Object
      implements IMocksControl, IExpectationSetters<Object>, Serializable

  Author:
    OFFIS, Tammo Freese
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `MocksControl.MockType` Deprecated. Use org.easymock.MockType

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Range` | `AT_LEAST_ONCE` One or more calls.
    `static Range` | `ONCE` Exactly one call.
    `static Range` | `ZERO_OR_MORE` Zero or more calls.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MocksControl(MocksControl.MockType type)`
    `MocksControl(MockType type)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `IExpectationSetters<Object>` | `andAnswer(IAnswer<? extends Object> answer)` Sets an object that will be used to calculate the answer for the expected invocation (either return a value, or throw an exception).
    `IExpectationSetters<Object>` | `andDelegateTo(Object answer)` Sets an object implementing the same interface as the mock.
    `IExpectationSetters<Object>` | `andReturn(Object value)` Sets a return value that will be returned for the expected invocation.
    `void` | `andStubAnswer(IAnswer<? extends Object> answer)` Sets a stub object that will be used to calculate the answer for the expected invocation (either return a value, or throw an exception).
    `void` | `andStubDelegateTo(Object delegateTo)` Sets a stub object implementing the same interface as the mock.
    `void` | `andStubReturn(Object value)` Sets a stub return value that will be returned for the expected invocation.
    `void` | `andStubThrow(Throwable throwable)` Sets a stub throwable that will be thrown for the expected invocation.
    `IExpectationSetters<Object>` | `andThrow(Throwable throwable)` Sets a throwable that will be thrown for the expected invocation.
    `IExpectationSetters<Object>` | `anyTimes()` Expect the last invocation any times.
    `void` | `asStub()` Sets stub behavior for the expected invocation (this is needed for void methods).
    `IExpectationSetters<Object>` | `atLeastOnce()` Expect the last invocation at least once.
    `void` | `checkIsUsedInOneThread(boolean shouldBeUsedInOneThread)` Check that the mock is called from only one thread
    `void` | `checkOrder(boolean value)` Switches order checking on and off.
    `<T> T` | `createMock(Class<T> toMock)` Creates a mock object that implements the given interface.
    `<T> T` | `createMock(Class<T> toMock, ConstructorArgs constructorArgs, Method... mockedMethods)` Deprecated.
    `<T> T` | `createMock(Class<T> toMock, Method... mockedMethods)` Deprecated.
    `<T> T` | `createMock(String name, Class<T> toMock)` Creates a mock object that implements the given interface.
    `<T> T` | `createMock(String name, Class<T> toMock, ConstructorArgs constructorArgs, Method... mockedMethods)` Deprecated.
    `<T> T` | `createMock(String name, Class<T> toMock, Method... mockedMethods)` Deprecated.
    `static MocksControl` | `getControl(Object mock)`
    `static InvocationHandler` | `getInvocationHandler(Object mock)`
    `static <T,V extends T> Class<T>` | `getMockedType(V proxy)` Return the class of interface (depending on the mock type) that was mocked
    `static IProxyFactory` | `getProxyFactory(Object o)`
    `IMocksControlState` | `getState()`
    `MockType` | `getType()`
    `void` | `makeThreadSafe(boolean threadSafe)` Makes the mock thread safe.
    `IExpectationSetters<Object>` | `once()` Expect the last invocation once.
    `void` | `replay()` Switches the control from record mode to replay mode.
    `void` | `reset()` Removes all expectations for the mock objects of this control.
    `void` | `resetToDefault()` Removes all expectations for the mock objects of this control and turn them to default mocks.
    `void` | `resetToNice()` Removes all expectations for the mock objects of this control and turn them to nice mocks.
    `void` | `resetToStrict()` Removes all expectations for the mock objects of this control and turn them to strict mocks.
    `IExpectationSetters<Object>` | `times(int times)` Expect the last invocation `count` times.
    `IExpectationSetters<Object>` | `times(int min, int max)` Expect the last invocation between `min` and `max` times.
    `void` | `verify()` Verifies that all expectations were met.

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

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

- - ### Field Detail

    - #### ONCE

          public static final Range ONCE

      Exactly one call.

    - #### AT_LEAST_ONCE

          public static final Range AT_LEAST_ONCE

      One or more calls.

    - #### ZERO_OR_MORE

          public static final Range ZERO_OR_MORE

      Zero or more calls.

  - ### Constructor Detail

    - #### MocksControl

          public MocksControl(MockType type)

    - #### MocksControl

          public MocksControl(MocksControl.MockType type)

  - ### Method Detail

    - #### getType

          public MockType getType()

    - #### getState

          public IMocksControlState getState()

    - #### createMock

          public <T> T createMock(Class<T> toMock)

      Description copied from interface: `IMocksControl`
      Creates a mock object that implements the given interface.
      Specified by:
        `createMock` in interface `IMocksControl`
      Type Parameters:
        `T` - the interface or class that the mock object should implement/extend.
      Parameters:
        `toMock` - the interface or class that the mock object should implement/extend.
      Returns:
        the mock object.

    - #### createMock

          public <T> T createMock(String name,
                         Class<T> toMock)

      Description copied from interface: `IMocksControl`
      Creates a mock object that implements the given interface.
      Specified by:
        `createMock` in interface `IMocksControl`
      Type Parameters:
        `T` - the interface or class that the mock object should implement/extend.
      Parameters:
        `name` - the name of the mock object.
        `toMock` - the interface or class that the mock object should implement/extend.
      Returns:
        the mock object.

    - #### createMock

          @Deprecated
          public <T> T createMock(String name,
                                    Class<T> toMock,
                                    Method... mockedMethods)

      Deprecated.
      Description copied from interface: `IMocksControl`
      Creates a mock object that implements the given class.
      Specified by:
        `createMock` in interface `IMocksControl`
      Type Parameters:
        `T` - the class that the mock object should extend.
      Parameters:
        `name` - the name of the mock object.
        `toMock` - the class that the mock object should extend.
        `mockedMethods` - methods that will be mocked, other methods will behave normally
      Returns:
        the mock object.

    - #### createMock

          @Deprecated
          public <T> T createMock(Class<T> toMock,
                                    Method... mockedMethods)

      Deprecated.
      Description copied from interface: `IMocksControl`
      Creates a mock object that implements the given class.
      Specified by:
        `createMock` in interface `IMocksControl`
      Type Parameters:
        `T` - the class that the mock object should extend.
      Parameters:
        `toMock` - the class that the mock object should extend.
        `mockedMethods` - methods that will be mocked, other methods will behave normally
      Returns:
        the mock object.

    - #### createMock

          @Deprecated
          public <T> T createMock(Class<T> toMock,
                                    ConstructorArgs constructorArgs,
                                    Method... mockedMethods)

      Deprecated.
      Description copied from interface: `IMocksControl`
      Creates a mock object that implements the given class.
      Specified by:
        `createMock` in interface `IMocksControl`
      Type Parameters:
        `T` - the class that the mock object should extend.
      Parameters:
        `toMock` - the class that the mock object should extend.
        `constructorArgs` - constructor and parameters used to instantiate the mock.
        `mockedMethods` - methods that will be mocked, other methods will behave normally
      Returns:
        the mock object.

    - #### createMock

          @Deprecated
          public <T> T createMock(String name,
                                    Class<T> toMock,
                                    ConstructorArgs constructorArgs,
                                    Method... mockedMethods)

      Deprecated.
      Description copied from interface: `IMocksControl`
      Creates a mock object that implements the given class.
      Specified by:
        `createMock` in interface `IMocksControl`
      Type Parameters:
        `T` - the class that the mock object should extend.
      Parameters:
        `name` - the name of the mock object.
        `toMock` - the class that the mock object should extend.
        `constructorArgs` - constructor and parameters used to instantiate the mock.
        `mockedMethods` - methods that will be mocked, other methods will behave normally
      Returns:
        the mock object.

    - #### getProxyFactory

          public static IProxyFactory getProxyFactory(Object o)

    - #### getControl

          public static MocksControl getControl(Object mock)

    - #### getInvocationHandler

          public static InvocationHandler getInvocationHandler(Object mock)

    - #### getMockedType

          public static <T,V extends T> Class<T> getMockedType(V proxy)

      Return the class of interface (depending on the mock type) that was mocked
      Type Parameters:
        `T` - Mocked class
        `V` - Mock class
      Parameters:
        `proxy` - Mock object
      Returns:
        the mocked class or interface

    - #### reset

          public final void reset()

      Description copied from interface: `IMocksControl`
      Removes all expectations for the mock objects of this control.
      Specified by:
        `reset` in interface `IMocksControl`

    - #### resetToNice

          public void resetToNice()

      Description copied from interface: `IMocksControl`
      Removes all expectations for the mock objects of this control and turn them to nice mocks.
      Specified by:
        `resetToNice` in interface `IMocksControl`

    - #### resetToDefault

          public void resetToDefault()

      Description copied from interface: `IMocksControl`
      Removes all expectations for the mock objects of this control and turn them to default mocks.
      Specified by:
        `resetToDefault` in interface `IMocksControl`

    - #### resetToStrict

          public void resetToStrict()

      Description copied from interface: `IMocksControl`
      Removes all expectations for the mock objects of this control and turn them to strict mocks.
      Specified by:
        `resetToStrict` in interface `IMocksControl`

    - #### replay

          public void replay()

      Description copied from interface: `IMocksControl`
      Switches the control from record mode to replay mode.
      Specified by:
        `replay` in interface `IMocksControl`

    - #### verify

          public void verify()

      Description copied from interface: `IMocksControl`
      Verifies that all expectations were met.
      Specified by:
        `verify` in interface `IMocksControl`

    - #### checkOrder

          public void checkOrder(boolean value)

      Description copied from interface: `IMocksControl`
      Switches order checking on and off.
      Specified by:
        `checkOrder` in interface `IMocksControl`
      Parameters:
        `value` - `true` switches order checking on, `false` switches it off.

    - #### makeThreadSafe

          public void makeThreadSafe(boolean threadSafe)

      Description copied from interface: `IMocksControl`
      Makes the mock thread safe.
      Specified by:
        `makeThreadSafe` in interface `IMocksControl`
      Parameters:
        `threadSafe` - If the mock should be thread safe or not

    - #### checkIsUsedInOneThread

          public void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread)

      Description copied from interface: `IMocksControl`
      Check that the mock is called from only one thread
      Specified by:
        `checkIsUsedInOneThread` in interface `IMocksControl`
      Parameters:
        `shouldBeUsedInOneThread` - If it should be used in one thread only or not

    - #### andReturn

          public IExpectationSetters<Object> andReturn(Object value)

      Description copied from interface: `IExpectationSetters`
      Sets a return value that will be returned for the expected invocation.
      Specified by:
        `andReturn` in interface `IExpectationSetters<Object>`
      Parameters:
        `value` - the value to return.
      Returns:
        this object to allow method call chaining.

    - #### andThrow

          public IExpectationSetters<Object> andThrow(Throwable throwable)

      Description copied from interface: `IExpectationSetters`
      Sets a throwable that will be thrown for the expected invocation.
      Specified by:
        `andThrow` in interface `IExpectationSetters<Object>`
      Parameters:
        `throwable` - the throwable to throw.
      Returns:
        this object to allow method call chaining.

    - #### andAnswer

          public IExpectationSetters<Object> andAnswer(IAnswer<? extends Object> answer)

      Description copied from interface: `IExpectationSetters`
      Sets an object that will be used to calculate the answer for the expected invocation (either return a value, or throw an exception).
      Specified by:
        `andAnswer` in interface `IExpectationSetters<Object>`
      Parameters:
        `answer` - the object used to answer the invocation.
      Returns:
        this object to allow method call chaining.

    - #### andDelegateTo

          public IExpectationSetters<Object> andDelegateTo(Object answer)

      Description copied from interface: `IExpectationSetters`
      Sets an object implementing the same interface as the mock. The expected method call will be delegated to it with the actual arguments. The answer returned by this call will then be the answer returned by the mock (either return a value, or throw an exception).
      Specified by:
        `andDelegateTo` in interface `IExpectationSetters<Object>`
      Parameters:
        `answer` - the object the call is delegated to.
      Returns:
        the value returned by the delegated call.

    - #### andStubReturn

          public void andStubReturn(Object value)

      Description copied from interface: `IExpectationSetters`
      Sets a stub return value that will be returned for the expected invocation.
      Specified by:
        `andStubReturn` in interface `IExpectationSetters<Object>`
      Parameters:
        `value` - the value to return.

    - #### andStubThrow

          public void andStubThrow(Throwable throwable)

      Description copied from interface: `IExpectationSetters`
      Sets a stub throwable that will be thrown for the expected invocation.
      Specified by:
        `andStubThrow` in interface `IExpectationSetters<Object>`
      Parameters:
        `throwable` - the throwable to throw.

    - #### andStubAnswer

          public void andStubAnswer(IAnswer<? extends Object> answer)

      Description copied from interface: `IExpectationSetters`
      Sets a stub object that will be used to calculate the answer for the expected invocation (either return a value, or throw an exception).
      Specified by:
        `andStubAnswer` in interface `IExpectationSetters<Object>`
      Parameters:
        `answer` - the object used to answer the invocation.

    - #### andStubDelegateTo

          public void andStubDelegateTo(Object delegateTo)

      Description copied from interface: `IExpectationSetters`
      Sets a stub object implementing the same interface as the mock. The expected method call will be delegated to it with the actual arguments. The answer returned by this call will then be the answer returned by the mock (either return a value, or throw an exception).
      Specified by:
        `andStubDelegateTo` in interface `IExpectationSetters<Object>`
      Parameters:
        `delegateTo` - the object the call is delegated to.

    - #### asStub

          public void asStub()

      Description copied from interface: `IExpectationSetters`
      Sets stub behavior for the expected invocation (this is needed for void methods).
      Specified by:
        `asStub` in interface `IExpectationSetters<Object>`

    - #### times

          public IExpectationSetters<Object> times(int times)

      Description copied from interface: `IExpectationSetters`
      Expect the last invocation `count` times.
      Specified by:
        `times` in interface `IExpectationSetters<Object>`
      Parameters:
        `times` - the number of invocations expected.
      Returns:
        this object to allow method call chaining.

    - #### times

          public IExpectationSetters<Object> times(int min,
                                          int max)

      Description copied from interface: `IExpectationSetters`
      Expect the last invocation between `min` and `max` times.
      Specified by:
        `times` in interface `IExpectationSetters<Object>`
      Parameters:
        `min` - the minimum number of invocations expected.
        `max` - the maximum number of invocations expected.
      Returns:
        this object to allow method call chaining.

    - #### once

          public IExpectationSetters<Object> once()

      Description copied from interface: `IExpectationSetters`
      Expect the last invocation once. This is default in EasyMock.
      Specified by:
        `once` in interface `IExpectationSetters<Object>`
      Returns:
        this object to allow method call chaining.

    - #### atLeastOnce

          public IExpectationSetters<Object> atLeastOnce()

      Description copied from interface: `IExpectationSetters`
      Expect the last invocation at least once.
      Specified by:
        `atLeastOnce` in interface `IExpectationSetters<Object>`
      Returns:
        this object to allow method call chaining.

    - #### anyTimes

          public IExpectationSetters<Object> anyTimes()

      Description copied from interface: `IExpectationSetters`
      Expect the last invocation any times.
      Specified by:
        `anyTimes` in interface `IExpectationSetters<Object>`
      Returns:
        this object to allow method call chaining.

Copyright © 2001-2013 OFFIS, Tammo Freese, Henri Tremblay. All Rights Reserved.