org.omnaest.utils.proxy
Class MethodCallCapturer

java.lang.Object
  extended by org.omnaest.utils.proxy.MethodCallCapturer

public class MethodCallCapturer
extends Object

A MethodCallCapturer allows to create stubs for given java types which capture the calls of methods of this stub.

Author:
Omnaest
See Also:
MethodName, BeanProperty, methodName, beanProperty, newInstanceOfCapturedType(Class), newInstanceOfCapturedTypeWhichIsMethodCallCapturerAware(Class), newInstanceOfTransitivlyCapturedType(Class), newInstanceOfTransitivlyCapturedTypeWhichIsMethodCallCapturerAware(Class), getMethodCallCaptureContextList(), #getCanonicalMethodNameToMethodCallCaptureMap(), MethodCallCapture

Nested Class Summary
protected static class MethodCallCapturer.CapturedTypeInstanceCreationConfiguration
          Configuration object when a MethodCallCapturer creates a new stub instance.
static class MethodCallCapturer.MethodCallCaptureContext
          Container class for the absolute canonical method name when a MethodCallCapture instance has been captured.
static interface MethodCallCapturer.MethodCallCapturerAware
          This interface stubs are implementing when they are created by newInstanceOfCapturedTypeWhichIsMethodCallCapturerAware(Class).
protected  class MethodCallCapturer.MethodCaptureMethodInvocationHandler
          MethodInterceptor for the MethodCallCapturer.
static class MethodCallCapturer.ReplayResult
          Result of a replay action.
static interface MethodCallCapturer.TypeCaptureAware
          This interface stubs are always implementing when they are created by newInstanceOfCapturedType(Class).
 
Field Summary
 BeanProperty beanProperty
           
protected  Object lastActiveRootStub
           
 MethodName methodName
           
protected  Map<Object,List<MethodCallCapturer.MethodCallCaptureContext>> stubToMethodCallCaptureContextListMap
           
 
Constructor Summary
MethodCallCapturer()
           
 
Method Summary
 List<String> getCapturedCanonicalMethodNameList()
          Returns a new list of all captured canonical method names for the last active stub object in order of their invocation.
 List<String> getCapturedCanonicalMethodNameList(Object stub)
          Returns a new list of all captured canonical method names for a given stub object in order of their invocation.
 List<String> getCapturedCanonicalMethodNameListWithMergedHierarchyCalls()
          Returns a List of the canonical method names captured by the last active stub.
 List<String> getCapturedCanonicalMethodNameListWithMergedHierarchyCalls(Object stub)
          Returns a List of the canonical method names captured by the given stub but with all hierarchical calls like testInterface.doTestSubInterface().doCalculateSomething() which result in testInterface testInterface.doTestSubInterface testInterface.doTestSubInterface.doCalculateSomething merged into a single representation like: testInterface.doTestSubInterface.doCalculateSomething
 List<String> getCapturedCanonicalPropertyNameList()
          Returns a new list of all captured canonical property names for the last active stub object in order of their invocation.
 List<String> getCapturedCanonicalPropertyNameList(Object stub)
          Returns a new list of all captured canonical property names for a given stub object in order of their invocation.
 List<String> getCapturedCanonicalPropertyNameListWithMergedHierarchyCalls()
          Returns a List of the canonical property names captured by the last active stub.
 List<String> getCapturedCanonicalPropertyNameListWithMergedHierarchyCalls(Object stub)
          Returns a List of the canonical method names captured by the given stub but with all hierarchical calls like testInterface.doTestSubInterface().doCalculateSomething() which result in testInterface testInterface.fieldObject testInterface.fieldObject.fieldString merged into a single representation like: testInterface.fieldObject.fieldString
 MethodCallCapturer.MethodCallCaptureContext getLastMethodCallContext()
          Returns the last MethodCallCapturer.MethodCallCaptureContext which has been reported to this MethodCallCapturer.
 List<MethodCallCapturer.MethodCallCaptureContext> getMethodCallCaptureContextList()
          Returns a new list instance of all MethodCallCapturer.MethodCallCaptureContext instances.
 List<MethodCallCapturer.MethodCallCaptureContext> getMethodCallCaptureContextList(Object stub)
          Returns a new list instance of all MethodCallCapturer.MethodCallCaptureContext instances for a given stub instance.
 List<MethodCallCapturer.MethodCallCaptureContext> getMethodCallCaptureContextWithMergedHierarchyList()
          Returns a new list instance of all MethodCallCapturer.MethodCallCaptureContext instances for the last active stub instance.
 List<MethodCallCapturer.MethodCallCaptureContext> getMethodCallCaptureContextWithMergedHierarchyList(Object stub)
          Returns a new list instance of all MethodCallCapturer.MethodCallCaptureContext instances for a given stub instance.
protected  List<MethodCallCapturer.MethodCallCaptureContext> getOrCreateMethodCallCaptureContextListForStub(Object stub)
          Gets an available list for the given proxy object or creates a new one.
protected  void mergeHierarchicalMethodCallCaptureContextList(List<MethodCallCapturer.MethodCallCaptureContext> hierarchicalMethodCallCaptureContextList)
          Merges hierarchies of MethodCallCapturer.MethodCallCaptureContexts into the most nested MethodCallCapturer.MethodCallCaptureContext for each group of MethodCallCapturer.MethodCallCaptureContexts
protected  void mergeHierarchicalNameList(List<String> hierarchicalNameList)
          Merges a list of hierarchical names.
<E> E
newInstanceOfCapturedType(Class<? extends E> clazz)
          Creates a new stub instance for the given class or interface which records all method invocations to this MethodCallCapturer.
protected
<E> E
newInstanceOfCapturedType(MethodCallCapturer.CapturedTypeInstanceCreationConfiguration capturedTypeInstanceCreationConfiguration)
           
<E> E
newInstanceOfCapturedTypeWhichIsMethodCallCapturerAware(Class<? extends E> clazz)
          Creates a new instance like newInstanceOfCapturedType(Class) but makes the created stub implementing the MethodCallCapturer.MethodCallCapturerAware interface which allows to get the underlying MethodCallCapturer through the generated stub.
<E> E
newInstanceOfTransitivlyCapturedType(Class<? extends E> clazz)
          Does create stubs whose objects returned by method invocations are stubs themselves.
<E> E
newInstanceOfTransitivlyCapturedTypeWhichIsMethodCallCapturerAware(Class<? extends E> clazz)
          Creates a stub which implements the MethodCallCapturer.MethodCallCapturerAware interface and which generates method returned objects which are stubs, too.
<E> MethodCallCapturer.ReplayResult
replay(E object)
          Replays the method invocations done to the last active stub for the given object like the object would have been invoked in the first place.
<E> MethodCallCapturer.ReplayResult
replay(E stub, E object)
          Replays the method invocations done to the given stub for the given object like the object would have been invoked in the first place.
 MethodCallCapturer reset()
          Resets the MethodCallCapturer.
 MethodCallCapturer reset(Object stub)
          Clears the captured method calls for a special stub object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

methodName

public final MethodName methodName

beanProperty

public final BeanProperty beanProperty

stubToMethodCallCaptureContextListMap

protected final Map<Object,List<MethodCallCapturer.MethodCallCaptureContext>> stubToMethodCallCaptureContextListMap

lastActiveRootStub

protected Object lastActiveRootStub
Constructor Detail

MethodCallCapturer

public MethodCallCapturer()
See Also:
MethodCallCapturer
Method Detail

newInstanceOfCapturedType

public <E> E newInstanceOfCapturedType(Class<? extends E> clazz)
Creates a new stub instance for the given class or interface which records all method invocations to this MethodCallCapturer.

See Also:
getMethodCallCaptureContextList(), MethodCallCapturer#getCanonicalMethodNameToMethodCallCaptureMap(), #methodNameOf(Object)

newInstanceOfCapturedTypeWhichIsMethodCallCapturerAware

public <E> E newInstanceOfCapturedTypeWhichIsMethodCallCapturerAware(Class<? extends E> clazz)
Creates a new instance like newInstanceOfCapturedType(Class) but makes the created stub implementing the MethodCallCapturer.MethodCallCapturerAware interface which allows to get the underlying MethodCallCapturer through the generated stub.

Type Parameters:
E -
Parameters:
clazz -
Returns:
See Also:
newInstanceOfCapturedType(Class)

newInstanceOfTransitivlyCapturedType

public <E> E newInstanceOfTransitivlyCapturedType(Class<? extends E> clazz)
Does create stubs whose objects returned by method invocations are stubs themselves. This allows to capture canonical method names.

Type Parameters:
E -
Parameters:
clazz -
Returns:
See Also:
newInstanceOfCapturedType(Class), #methodNameOf(Object)

newInstanceOfTransitivlyCapturedTypeWhichIsMethodCallCapturerAware

public <E> E newInstanceOfTransitivlyCapturedTypeWhichIsMethodCallCapturerAware(Class<? extends E> clazz)
Creates a stub which implements the MethodCallCapturer.MethodCallCapturerAware interface and which generates method returned objects which are stubs, too.

Type Parameters:
E -
Parameters:
clazz -
Returns:
See Also:
newInstanceOfCapturedType(Class), newInstanceOfCapturedTypeWhichIsMethodCallCapturerAware(Class), newInstanceOfTransitivlyCapturedType(Class)

newInstanceOfCapturedType

protected <E> E newInstanceOfCapturedType(MethodCallCapturer.CapturedTypeInstanceCreationConfiguration capturedTypeInstanceCreationConfiguration)
Type Parameters:
E -
Parameters:
capturedTypeInstanceCreationConfiguration -
Returns:
See Also:
newInstanceOfCapturedType(Class), newInstanceOfCapturedTypeWhichIsMethodCallCapturerAware(Class), newInstanceOfTransitivlyCapturedType(Class), newInstanceOfTransitivlyCapturedTypeWhichIsMethodCallCapturerAware(Class)

getOrCreateMethodCallCaptureContextListForStub

protected List<MethodCallCapturer.MethodCallCaptureContext> getOrCreateMethodCallCaptureContextListForStub(Object stub)
Gets an available list for the given proxy object or creates a new one.

Parameters:
stub -
Returns:

getMethodCallCaptureContextList

public List<MethodCallCapturer.MethodCallCaptureContext> getMethodCallCaptureContextList()
Returns a new list instance of all MethodCallCapturer.MethodCallCaptureContext instances.

Returns:

getMethodCallCaptureContextList

public List<MethodCallCapturer.MethodCallCaptureContext> getMethodCallCaptureContextList(Object stub)
Returns a new list instance of all MethodCallCapturer.MethodCallCaptureContext instances for a given stub instance.

Parameters:
stub -
Returns:

getMethodCallCaptureContextWithMergedHierarchyList

public List<MethodCallCapturer.MethodCallCaptureContext> getMethodCallCaptureContextWithMergedHierarchyList()
Returns a new list instance of all MethodCallCapturer.MethodCallCaptureContext instances for the last active stub instance. All MethodCallCapturer.MethodCallCaptureContext instances coming before an MethodCallCapturer.MethodCallCaptureContext which is based on a nested call within the previous context will be merged into the nested call MethodCallCapturer.MethodCallCaptureContext.

Returns:

getMethodCallCaptureContextWithMergedHierarchyList

public List<MethodCallCapturer.MethodCallCaptureContext> getMethodCallCaptureContextWithMergedHierarchyList(Object stub)
Returns a new list instance of all MethodCallCapturer.MethodCallCaptureContext instances for a given stub instance. All MethodCallCapturer.MethodCallCaptureContext instances coming before an MethodCallCapturer.MethodCallCaptureContext which is based on a nested call within the previous context will be merged into the nested call MethodCallCapturer.MethodCallCaptureContext.

Parameters:
stub -
Returns:

getLastMethodCallContext

public MethodCallCapturer.MethodCallCaptureContext getLastMethodCallContext()
Returns the last MethodCallCapturer.MethodCallCaptureContext which has been reported to this MethodCallCapturer.

Returns:

reset

public MethodCallCapturer reset()
Resets the MethodCallCapturer.

Returns:
this

reset

public MethodCallCapturer reset(Object stub)
Clears the captured method calls for a special stub object.

Parameters:
stub -
Returns:
this

getCapturedCanonicalPropertyNameList

public List<String> getCapturedCanonicalPropertyNameList()
Returns a new list of all captured canonical property names for the last active stub object in order of their invocation. (First invocation is the first entry)

Returns:
See Also:
getCapturedCanonicalMethodNameList()

getCapturedCanonicalPropertyNameList

public List<String> getCapturedCanonicalPropertyNameList(Object stub)
Returns a new list of all captured canonical property names for a given stub object in order of their invocation. (First invocation is the first entry)

Parameters:
stub -
Returns:
See Also:
getCapturedCanonicalMethodNameList()

getCapturedCanonicalMethodNameList

public List<String> getCapturedCanonicalMethodNameList(Object stub)
Returns a new list of all captured canonical method names for a given stub object in order of their invocation. (First invocation is the first entry)

Parameters:
stub -
Returns:
See Also:
getCapturedCanonicalMethodNameList()

getCapturedCanonicalMethodNameList

public List<String> getCapturedCanonicalMethodNameList()
Returns a new list of all captured canonical method names for the last active stub object in order of their invocation. (First invocation is the first entry)

Returns:
See Also:
getCapturedCanonicalMethodNameListWithMergedHierarchyCalls(Object)

getCapturedCanonicalMethodNameListWithMergedHierarchyCalls

public List<String> getCapturedCanonicalMethodNameListWithMergedHierarchyCalls()
Returns a List of the canonical method names captured by the last active stub.

Returns:
See Also:
getCapturedCanonicalMethodNameListWithMergedHierarchyCalls(Object)

getCapturedCanonicalPropertyNameListWithMergedHierarchyCalls

public List<String> getCapturedCanonicalPropertyNameListWithMergedHierarchyCalls()
Returns a List of the canonical property names captured by the last active stub.

Returns:
See Also:
getCapturedCanonicalPropertyNameListWithMergedHierarchyCalls(Object)

getCapturedCanonicalPropertyNameListWithMergedHierarchyCalls

public List<String> getCapturedCanonicalPropertyNameListWithMergedHierarchyCalls(Object stub)
Returns a List of the canonical method names captured by the given stub but with all hierarchical calls like testInterface.doTestSubInterface().doCalculateSomething() which result in merged into a single representation like:

Parameters:
stub -
Returns:
See Also:
getCapturedCanonicalPropertyNameListWithMergedHierarchyCalls(), getCapturedCanonicalMethodNameListWithMergedHierarchyCalls(Object)

getCapturedCanonicalMethodNameListWithMergedHierarchyCalls

public List<String> getCapturedCanonicalMethodNameListWithMergedHierarchyCalls(Object stub)
Returns a List of the canonical method names captured by the given stub but with all hierarchical calls like testInterface.doTestSubInterface().doCalculateSomething() which result in merged into a single representation like:

Parameters:
stub -
Returns:
See Also:
getCapturedCanonicalMethodNameList(), getCapturedCanonicalMethodNameListWithMergedHierarchyCalls()

mergeHierarchicalNameList

protected void mergeHierarchicalNameList(List<String> hierarchicalNameList)
Merges a list of hierarchical names. E.g. testInterface.doTestSubInterface().doCalculateSomething() which result in merged into a single representation like:

Parameters:
hierarchicalNameList -

mergeHierarchicalMethodCallCaptureContextList

protected void mergeHierarchicalMethodCallCaptureContextList(List<MethodCallCapturer.MethodCallCaptureContext> hierarchicalMethodCallCaptureContextList)
Merges hierarchies of MethodCallCapturer.MethodCallCaptureContexts into the most nested MethodCallCapturer.MethodCallCaptureContext for each group of MethodCallCapturer.MethodCallCaptureContexts

Parameters:
hierarchicalMethodCallCaptureContextList -

replay

public <E> MethodCallCapturer.ReplayResult replay(E object)
Replays the method invocations done to the last active stub for the given object like the object would have been invoked in the first place.

Parameters:
object -
See Also:
replay(Object, Object)

replay

public <E> MethodCallCapturer.ReplayResult replay(E stub,
                                                  E object)
Replays the method invocations done to the given stub for the given object like the object would have been invoked in the first place.

Parameters:
stub -
object -
Returns:
MethodCallCapturer.ReplayResult
See Also:
replay(Object)


Copyright © 2013. All Rights Reserved.