T - type of the mock createdpublic class MockBuilder<T> extends java.lang.Object implements IMockBuilder<T>
The original idea and part of the code where contributed by Rodrigo Damazio and Bruno Fonseca at Google
| Modifier and Type | Field and Description |
|---|---|
private static ReflectionUtils.Predicate<java.lang.reflect.Method> |
CAN_BE_MOCKED |
private java.lang.reflect.Constructor<?> |
constructor |
private ConstructorArgs |
constructorArgs |
private java.util.Set<java.lang.reflect.Method> |
mockedMethods |
private EasyMockSupport |
support |
private java.lang.Class<?> |
toMock |
| Constructor and Description |
|---|
MockBuilder(java.lang.Class<?> toMock) |
MockBuilder(java.lang.Class<?> toMock,
EasyMockSupport support)
Used by EasyMockSupport to allow the mock registration in the list of
controls
|
| 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.
|
private void |
checkConstructorNotInitialized() |
<R> R |
createMock()
Create a default mock 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 |
createMock(java.lang.String name)
Create named mock from the provided mock control using the arguments
passed to the builder.
|
<R> R |
createMock(java.lang.String name,
IMocksControl control)
Create named mock from the provided mock control using the arguments
passed to the builder.
|
<R> R |
createMock(java.lang.String name,
MockType type)
Create a named mock of the request type from this builder.
|
<R> R |
createNiceMock()
Create a nice mock from this builder.
|
<R> R |
createNiceMock(java.lang.String name)
Create a named nice mock from this builder.
|
<R> R |
createStrictMock()
Create a strict mock from this builder.
|
<R> R |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitmock, mock, mock, mock, mock, mock, niceMock, niceMock, strictMock, strictMockprivate static final ReflectionUtils.Predicate<java.lang.reflect.Method> CAN_BE_MOCKED
private final java.lang.Class<?> toMock
private java.util.Set<java.lang.reflect.Method> mockedMethods
private java.lang.reflect.Constructor<?> constructor
private ConstructorArgs constructorArgs
private final EasyMockSupport support
public MockBuilder(java.lang.Class<?> toMock)
public MockBuilder(java.lang.Class<?> toMock,
EasyMockSupport support)
toMock - The class of the mock to createsupport - The EasyMockSupport used to create mocks. Null if nonepublic IMockBuilder<T> addMockedMethod(java.lang.reflect.Method method)
IMockBuilderaddMockedMethod in interface IMockBuilder<T>method - method to be mockedpublic IMockBuilder<T> addMockedMethod(java.lang.String methodName)
IMockBuilderaddMockedMethods in this class if that is the case.addMockedMethod in interface IMockBuilder<T>methodName - name of the method to be mockedpublic IMockBuilder<T> addMockedMethod(java.lang.String methodName, java.lang.Class<?>... parameterTypes)
IMockBuilderaddMockedMethod in interface IMockBuilder<T>methodName - name of the method to be mockedparameterTypes - types of the parameters of the methodpublic IMockBuilder<T> addMockedMethods(java.lang.String... methodNames)
IMockBuilderIMockBuilder.addMockedMethod(String) but to mock many methods at once.addMockedMethods in interface IMockBuilder<T>methodNames - names of the methods to be mockedpublic IMockBuilder<T> addMockedMethods(java.lang.reflect.Method... methods)
IMockBuilderIMockBuilder.addMockedMethod(Method) but to mock many methods at once.addMockedMethods in interface IMockBuilder<T>methods - methods to be mockedpublic IMockBuilder<T> withConstructor(java.lang.reflect.Constructor<?> constructor)
IMockBuilderIMockBuilder.withArgs(java.lang.Object...) with the actual constructor argument
values after this.withConstructor in interface IMockBuilder<T>constructor - the constructor to be calledpublic IMockBuilder<T> withConstructor(ConstructorArgs constructorArgs)
public IMockBuilder<T> withConstructor()
IMockBuilderwithConstructor in interface IMockBuilder<T>public IMockBuilder<T> withConstructor(java.lang.Object... initArgs)
IMockBuilderwithConstructor in interface IMockBuilder<T>initArgs - arguments of the constructorpublic IMockBuilder<T> withConstructor(java.lang.Class<?>... argTypes)
IMockBuilderIMockBuilder.withArgs(java.lang.Object...) with the actual constructor
argument values after this.withConstructor in interface IMockBuilder<T>argTypes - the exact argument types of the constructorpublic IMockBuilder<T> withArgs(java.lang.Object... initArgs)
IMockBuilderIMockBuilder.withConstructor(Class...) or
IMockBuilder.withConstructor(Constructor).withArgs in interface IMockBuilder<T>initArgs - the arguments to pass to the constructorpublic <R> R createMock(MockType type)
IMockBuildercreateMock in interface IMockBuilder<T>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 typetype - the mock typepublic <R> R createMock(java.lang.String name,
MockType type)
IMockBuildercreateMock in interface IMockBuilder<T>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 typename - the mock nametype - the mock typepublic <R> R createMock(IMocksControl control)
IMockBuildercreateMock in interface IMockBuilder<T>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 typecontrol - IMocksControl used to create the objectpublic <R> R createMock()
IMockBuildercreateMock in interface IMockBuilder<T>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 typepublic <R> R createNiceMock()
IMockBuildercreateNiceMock in interface IMockBuilder<T>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 typepublic <R> R createStrictMock()
IMockBuildercreateStrictMock in interface IMockBuilder<T>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 typepublic <R> R createMock(java.lang.String name,
IMocksControl control)
IMockBuildercreateMock in interface IMockBuilder<T>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 typename - the mock namecontrol - IMocksControl used to create the objectpublic <R> R createMock(java.lang.String name)
IMockBuildercreateMock in interface IMockBuilder<T>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 typename - the mock namepublic <R> R createNiceMock(java.lang.String name)
IMockBuildercreateNiceMock in interface IMockBuilder<T>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 typename - the mock namepublic <R> R createStrictMock(java.lang.String name)
IMockBuildercreateStrictMock in interface IMockBuilder<T>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 typename - the mock nameprivate void checkConstructorNotInitialized()