java.lang.Object
org.easymock.internal.MockBuilder<T>
- Type Parameters:
T
- type of the mock created
- All Implemented Interfaces:
IMockBuilder<T>
Default implementation of IMockBuilder.
The original idea and part of the code where contributed by Rodrigo Damazio and Bruno Fonseca at Google
- Author:
- Henri Tremblay
-
Constructor Summary
ConstructorDescriptionMockBuilder
(Class<?> toMock) MockBuilder
(Class<?> toMock, EasyMockSupport support) Used by EasyMockSupport to allow the mock registration in the list of controls -
Method Summary
Modifier and TypeMethodDescriptionaddMockedMethod
(Method method) Adds a method to be mocked in the testing class.addMockedMethod
(String methodName) Adds a method to be mocked in the testing class.addMockedMethod
(String methodName, Class<?>... parameterTypes) Adds a method to be mocked in the testing class.addMockedMethods
(Method... methods) Adds methods to be mocked in the testing class.addMockedMethods
(String... methodNames) Adds methods to be mocked in the testing class.<R> R
Create a default mock from this builder.<R> R
createMock
(String name) Create named mock from the provided mock control using the arguments passed to the builder.<R> R
createMock
(String name, IMocksControl control) Create named mock from the provided mock control using the arguments passed to the builder.<R> R
createMock
(String name, MockType type) Create a named mock of the request type from this builder.<R> R
createMock
(IMocksControl control) Create mock from the provided mock control using the arguments passed to the builder.<R> R
createMock
(MockType type) Create mock of the request type from this builder.<R> R
Create a nice mock from this builder.<R> R
createNiceMock
(String name) Create a named nice mock from this builder.<R> R
Create a strict mock from this builder.<R> R
createStrictMock
(String name) Create a named strict mock from this builder.Defines the arguments to be passed to the constructor of the class.Defines the empty constructor should be called.withConstructor
(Class<?>... argTypes) Defines the exact argument types for the constructor to use.withConstructor
(Object... initArgs) Defines the constructor parameters for the mocked class.withConstructor
(Constructor<?> constructor) Defines the constructor to use to instantiate the mock.withConstructor
(ConstructorArgs constructorArgs) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.easymock.IMockBuilder
mock, mock, mock, mock, mock, mock, niceMock, niceMock, strictMock, strictMock
-
Constructor Details
-
MockBuilder
-
MockBuilder
Used by EasyMockSupport to allow the mock registration in the list of controls- Parameters:
toMock
- The class of the mock to createsupport
- The EasyMockSupport used to create mocks. Null if none
-
-
Method Details
-
addMockedMethod
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 interfaceIMockBuilder<T>
- Parameters:
method
- method to be mocked- Returns:
- this
-
addMockedMethod
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 otheraddMockedMethod
s in this class if that is the case.- Specified by:
addMockedMethod
in interfaceIMockBuilder<T>
- Parameters:
methodName
- name of the method to be mocked- Returns:
- this
-
addMockedMethod
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 interfaceIMockBuilder<T>
- Parameters:
methodName
- name of the method to be mockedparameterTypes
- types of the parameters of the method- Returns:
- this
-
addMockedMethods
Description copied from interface:IMockBuilder
Adds methods to be mocked in the testing class. Same asIMockBuilder.addMockedMethod(String)
but to mock many methods at once.- Specified by:
addMockedMethods
in interfaceIMockBuilder<T>
- Parameters:
methodNames
- names of the methods to be mocked- Returns:
- this
-
addMockedMethods
Description copied from interface:IMockBuilder
Adds methods to be mocked in the testing class. Same asIMockBuilder.addMockedMethod(Method)
but to mock many methods at once.- Specified by:
addMockedMethods
in interfaceIMockBuilder<T>
- Parameters:
methods
- methods to be mocked- Returns:
- this
-
withConstructor
Description copied from interface:IMockBuilder
Defines the constructor to use to instantiate the mock. It is expected that you callIMockBuilder.withArgs(java.lang.Object...)
with the actual constructor argument values after this.- Specified by:
withConstructor
in interfaceIMockBuilder<T>
- Parameters:
constructor
- the constructor to be called- Returns:
- this
-
withConstructor
-
withConstructor
Description copied from interface:IMockBuilder
Defines the empty constructor should be called.- Specified by:
withConstructor
in interfaceIMockBuilder<T>
- Returns:
- this
-
withConstructor
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 interfaceIMockBuilder<T>
- Parameters:
initArgs
- arguments of the constructor- Returns:
- this
-
withConstructor
Description copied from interface:IMockBuilder
Defines the exact argument types for the constructor to use. It is expected that you callIMockBuilder.withArgs(java.lang.Object...)
with the actual constructor argument values after this.- Specified by:
withConstructor
in interfaceIMockBuilder<T>
- Parameters:
argTypes
- the exact argument types of the constructor- Returns:
- this
-
withArgs
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 withIMockBuilder.withConstructor(Class...)
orIMockBuilder.withConstructor(Constructor)
.- Specified by:
withArgs
in interfaceIMockBuilder<T>
- Parameters:
initArgs
- the arguments to pass to the constructor- Returns:
- this
-
createMock
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 interfaceIMockBuilder<T>
- Type Parameters:
R
- the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the caller, we return a different type- Parameters:
type
- the mock type- Returns:
- the newly created mock
-
createMock
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 interfaceIMockBuilder<T>
- Type Parameters:
R
- the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the caller, we return a different type- Parameters:
name
- the mock nametype
- the mock type- Returns:
- the newly created mock
-
createMock
Description copied from interface:IMockBuilder
Create mock from the provided mock control using the arguments passed to the builder.- Specified by:
createMock
in interfaceIMockBuilder<T>
- Type Parameters:
R
- the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the caller, we return a different type- Parameters:
control
-IMocksControl
used to create the object- Returns:
- the newly created mock
-
createMock
public <R> R 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 interfaceIMockBuilder<T>
- Type Parameters:
R
- the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the caller, we return a different type- Returns:
- the newly created mock
-
createNiceMock
public <R> R 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 interfaceIMockBuilder<T>
- Type Parameters:
R
- the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the caller, we return a different type- Returns:
- the newly created mock
-
createStrictMock
public <R> R 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 interfaceIMockBuilder<T>
- Type Parameters:
R
- the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the caller, we return a different type- Returns:
- the newly created mock
-
createMock
Description copied from interface:IMockBuilder
Create named mock from the provided mock control using the arguments passed to the builder.- Specified by:
createMock
in interfaceIMockBuilder<T>
- Type Parameters:
R
- the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the caller, we return a different type- Parameters:
name
- the mock namecontrol
-IMocksControl
used to create the object- Returns:
- the newly created mock
-
createMock
Description copied from interface:IMockBuilder
Create named mock from the provided mock control using the arguments passed to the builder.- Specified by:
createMock
in interfaceIMockBuilder<T>
- Type Parameters:
R
- the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the caller, we return a different type- Parameters:
name
- the mock name- Returns:
- the newly created mock
-
createNiceMock
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 interfaceIMockBuilder<T>
- Type Parameters:
R
- the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the caller, we return a different type- Parameters:
name
- the mock name- Returns:
- the newly created mock
-
createStrictMock
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 interfaceIMockBuilder<T>
- Type Parameters:
R
- the returned type. In general T == R but when mocking a generic type, it won't so to be nice with the caller, we return a different type- Parameters:
name
- the mock name- Returns:
- the newly created mock
-