java - Checking if an EasyMock mock is on replay mode/state -


is possible determine if easymock mock on replay mode?

something like:

if (easymock.isreplayed(mock))   // 

in order check state of mock need unproxy mock , check state set mock, , 1 state replaystate. easymock works java proxies, quite easy:

easymock.replay(mock); // setting replay state mock object  // stripping proxy , getting invocation handler invocationhandler invocationhandler = proxy.getinvocationhandler(mock);    // easymock, invocation handler holds state of mock  objectmethodsfilter objectmethodsfilter = (objectmethodsfilter) invocationhandler;   // not not elegant part: // this: objectmethodsfilter.getdelegate().getcontrol().getstate()  // retrieves  state instance can checked if  // instance of replaystate.class boolean inreplaystate = objectmethodsfilter.getdelegate()     .getcontrol().getstate() instanceof replaystate; 

and thats it! print true because set replay

maybe version 3.1 use:

classextensionhelper.getcontrol(mock).getstate() instanceof replaystate 

classextensionhelper.getcontrol() javadoc


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -