loomis
unread,Jul 9, 2010, 4:09:20 PM7/9/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mockito-flex
Below there is a message I got from Peter, hope he does not mind:
Here's some async stuff I threw together today. Helps with rpc and
callbacks. Ever need to mock a ResultEvent?
Maybe you can incorporate this into the next release, and possibly on
the Stubber and integrations for convenience(i.e. callback() instead
of having to instantiate it).
internal class CallbackAnswer implements Answer, StubbingContextAware
{
private var _stubbingContext:StubbingContext;
private var _index:int;
private var _args:Array;
public function CallbackAnswer(index:int, args:Array = null) {
_index = index;
_args = args;
}
public function give():* {
if (!_stubbingContext)
throw new IllegalOperationError("A stubbing context has not been set
or an answer has been given already");
var callback:Function = _stubbingContext.args[_index] as Function;
return callback.apply(null, _args);
}
public function useContext(stubbingContext:StubbingContext):void {
_stubbingContext = stubbingContext;
}
}
Example:
given(mockService.someRPC(any(), anyOf(Function),
anyOf(Function))).will(new CallbackAnswer(1, [ResultEvent.create(new
Foo())]));
Or make me a contributor :)
-Peter Babinski