public class MockRepository
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.lang.Object> |
additionalState
Sometimes mock frameworks needs to store additional state.
|
private static java.util.Set<java.lang.Runnable> |
afterMethodRunners
Set of runnables that will be executed after the test (method) is completed.
|
private static java.util.Map<java.lang.Class<?>,MethodInvocationControl> |
classMocks
Holds info about general method invocation mocks for classes.
|
private static java.util.Map<java.lang.Object,MethodInvocationControl> |
instanceMocks
Holds info about general method invocation mocks for instances.
|
private static java.util.Map<java.lang.reflect.Method,java.lang.reflect.InvocationHandler> |
methodProxies
Holds info about which methods that are proxied.
|
private static java.util.Map<java.lang.Class<?>,NewInvocationControl<?>> |
newSubstitutions |
private static java.util.Set<java.lang.Object> |
objectsToAutomaticallyReplayAndVerify |
private static java.util.Map<java.lang.reflect.Method,java.lang.Object> |
substituteReturnValues
Holds info about which methods that should return a substitute/another
instance instead of the default instance.
|
private static java.util.Set<java.lang.reflect.Constructor<?>> |
suppressConstructor
Set of constructors that should be suppressed.
|
private static java.util.Set<java.lang.reflect.Field> |
suppressField
Set of methods that should be suppressed.
|
private static java.util.Set<java.lang.String> |
suppressFieldTypes
Set of field types that should always be suppressed regardless of
instance.
|
private static java.util.Set<java.lang.reflect.Method> |
suppressMethod
Set of methods that should be suppressed.
|
private static java.util.Set<java.lang.String> |
suppressStaticInitializers
Holds info about which class that should have their static initializers
suppressed.
|
Constructor and Description |
---|
MockRepository() |
Modifier and Type | Method and Description |
---|---|
static void |
addAfterMethodRunner(java.lang.Runnable runnable)
Add a
Runnable that will be executed after each test |
static void |
addConstructorToSuppress(java.lang.reflect.Constructor<?> constructor)
Add a constructor to suppress.
|
static void |
addFieldToSuppress(java.lang.reflect.Field field)
Add a field to suppress.
|
static void |
addFieldTypeToSuppress(java.lang.String fieldType)
Add a field type to suppress.
|
static void |
addMethodToSuppress(java.lang.reflect.Method method)
Add a method to suppress.
|
static void |
addObjectsToAutomaticallyReplayAndVerify(java.lang.Object... objects)
Add classes that should be automatically replayed or verified.
|
static void |
addSuppressStaticInitializer(java.lang.String className)
Add a fully qualified class name for a class that should have its static
initializers suppressed.
|
static void |
clear()
Clear all state of the mock repository except for static initializers.
|
static <T> T |
getAdditionalState(java.lang.String key)
Retrieve state based on the supplied key.
|
static MethodInvocationControl |
getInstanceMethodInvocationControl(java.lang.Object instance) |
static java.lang.reflect.InvocationHandler |
getMethodProxy(java.lang.reflect.Method method) |
static java.lang.Object |
getMethodToStub(java.lang.reflect.Method method) |
static NewInvocationControl<?> |
getNewInstanceControl(java.lang.Class<?> type) |
static java.util.Set<java.lang.Object> |
getObjectsToAutomaticallyReplayAndVerify() |
static MethodInvocationControl |
getStaticMethodInvocationControl(java.lang.Class<?> type) |
static boolean |
hasMethodProxy(java.lang.reflect.Method method) |
static java.lang.Object |
putAdditionalState(java.lang.String key,
java.lang.Object value)
When a mock framework API needs to store additional state not applicable
for the other methods, it may use this method to do so.
|
static MethodInvocationControl |
putInstanceMethodInvocationControl(java.lang.Object instance,
MethodInvocationControl invocationControl) |
static java.lang.reflect.InvocationHandler |
putMethodProxy(java.lang.reflect.Method method,
java.lang.reflect.InvocationHandler invocationHandler)
Set a proxy for a method.
|
static java.lang.Object |
putMethodToStub(java.lang.reflect.Method method,
java.lang.Object value)
Set a substitute return value for a method.
|
static NewInvocationControl<?> |
putNewInstanceControl(java.lang.Class<?> type,
NewInvocationControl<?> control) |
static MethodInvocationControl |
putStaticMethodInvocationControl(java.lang.Class<?> type,
MethodInvocationControl invocationControl) |
static void |
remove(java.lang.Object mock)
Removes an object from the MockRepository if it exists.
|
static java.lang.Object |
removeAdditionalState(java.lang.String key) |
static MethodInvocationControl |
removeClassMethodInvocationControl(java.lang.Class<?> type) |
static MethodInvocationControl |
removeInstanceMethodInvocationControl(java.lang.Class<?> type) |
static java.lang.reflect.InvocationHandler |
removeMethodProxy(java.lang.reflect.Method method) |
static void |
removeSuppressStaticInitializer(java.lang.String className)
Remove a fully qualified class name for a class that should no longer
have its static initializers suppressed.
|
static boolean |
shouldStubMethod(java.lang.reflect.Method method) |
static boolean |
shouldSuppressConstructor(java.lang.reflect.Constructor<?> constructor) |
static boolean |
shouldSuppressField(java.lang.reflect.Field field) |
static boolean |
shouldSuppressMethod(java.lang.reflect.Method method,
java.lang.Class<?> objectType) |
static boolean |
shouldSuppressStaticInitializerFor(java.lang.String className)
Check whether or not a class with the fully qualified name should have
its static initializers suppressed.
|
private static java.util.Set<java.lang.Object> objectsToAutomaticallyReplayAndVerify
private static java.util.Map<java.lang.Class<?>,NewInvocationControl<?>> newSubstitutions
private static java.util.Map<java.lang.Class<?>,MethodInvocationControl> classMocks
private static java.util.Map<java.lang.Object,MethodInvocationControl> instanceMocks
private static java.util.Map<java.lang.reflect.Method,java.lang.Object> substituteReturnValues
private static java.util.Map<java.lang.reflect.Method,java.lang.reflect.InvocationHandler> methodProxies
private static java.util.Set<java.lang.String> suppressStaticInitializers
private static java.util.Map<java.lang.String,java.lang.Object> additionalState
private static final java.util.Set<java.lang.reflect.Constructor<?>> suppressConstructor
private static final java.util.Set<java.lang.reflect.Method> suppressMethod
private static final java.util.Set<java.lang.reflect.Field> suppressField
private static final java.util.Set<java.lang.String> suppressFieldTypes
private static final java.util.Set<java.lang.Runnable> afterMethodRunners
public static void clear()
public static void remove(java.lang.Object mock)
public static MethodInvocationControl getStaticMethodInvocationControl(java.lang.Class<?> type)
public static MethodInvocationControl putStaticMethodInvocationControl(java.lang.Class<?> type, MethodInvocationControl invocationControl)
public static MethodInvocationControl removeClassMethodInvocationControl(java.lang.Class<?> type)
public static MethodInvocationControl getInstanceMethodInvocationControl(java.lang.Object instance)
public static MethodInvocationControl putInstanceMethodInvocationControl(java.lang.Object instance, MethodInvocationControl invocationControl)
public static MethodInvocationControl removeInstanceMethodInvocationControl(java.lang.Class<?> type)
public static NewInvocationControl<?> getNewInstanceControl(java.lang.Class<?> type)
public static NewInvocationControl<?> putNewInstanceControl(java.lang.Class<?> type, NewInvocationControl<?> control)
public static void addSuppressStaticInitializer(java.lang.String className)
className
- The fully qualified class name for a class that should have
its static initializers suppressed.public static void removeSuppressStaticInitializer(java.lang.String className)
className
- The fully qualified class name for a class that should no
longer have its static initializers suppressed.public static boolean shouldSuppressStaticInitializerFor(java.lang.String className)
className
- true
if class with the fully qualified name
className
should have its static initializers
suppressed, false
otherwise.public static java.util.Set<java.lang.Object> getObjectsToAutomaticallyReplayAndVerify()
public static void addObjectsToAutomaticallyReplayAndVerify(java.lang.Object... objects)
public static java.lang.Object putAdditionalState(java.lang.String key, java.lang.Object value)
key
- The key under which the value is stored.value
- The value to store under the specified key.null
.public static java.lang.Object removeAdditionalState(java.lang.String key)
public static java.lang.reflect.InvocationHandler removeMethodProxy(java.lang.reflect.Method method)
public static <T> T getAdditionalState(java.lang.String key)
public static void addMethodToSuppress(java.lang.reflect.Method method)
method
- The method to suppress.public static void addFieldToSuppress(java.lang.reflect.Field field)
field
- The field to suppress.public static void addFieldTypeToSuppress(java.lang.String fieldType)
fieldType
- The fully-qualified name to a type. All fields of this type
will be suppressed.public static void addConstructorToSuppress(java.lang.reflect.Constructor<?> constructor)
constructor
- The constructor to suppress.public static boolean hasMethodProxy(java.lang.reflect.Method method)
true
if the method should be proxied.public static boolean shouldSuppressMethod(java.lang.reflect.Method method, java.lang.Class<?> objectType) throws java.lang.ClassNotFoundException
true
if the method should be suppressed.java.lang.ClassNotFoundException
public static boolean shouldSuppressField(java.lang.reflect.Field field)
true
if the field should be suppressed.public static boolean shouldSuppressConstructor(java.lang.reflect.Constructor<?> constructor)
true
if the constructor should be
suppressed.public static boolean shouldStubMethod(java.lang.reflect.Method method)
true
if the method has a substitute return
value.public static java.lang.Object getMethodToStub(java.lang.reflect.Method method)
null
.public static java.lang.Object putMethodToStub(java.lang.reflect.Method method, java.lang.Object value)
value
will be returned instead.public static java.lang.reflect.InvocationHandler getMethodProxy(java.lang.reflect.Method method)
null
.public static java.lang.reflect.InvocationHandler putMethodProxy(java.lang.reflect.Method method, java.lang.reflect.InvocationHandler invocationHandler)
public static void addAfterMethodRunner(java.lang.Runnable runnable)
Runnable
that will be executed after each testrunnable
-