/**
* Checks if a EasyMock mock is in the replay state.
*
* @param mock to check replay state for
* @return true if the mock is in replay state, false if not or if the param
* is no mock
*/
public boolean isInReplayState(final Object mock) {
InvocationHandler invocationHandler = Proxy.getInvocationHandler(mock);
ObjectMethodsFilter objectMethodsFilter = (ObjectMethodsFilter) invocationHandler;
// not the not so elegant part:
// this: objectMethodsFilter.getDelegate().getControl().getState()
// retrieves the state instance that can be checked if it is an
// instance of ReplayState.class
return objectMethodsFilter.getDelegate()
.getControl().getState() instanceof ReplayState;
}