Re: [mockito-flex] Potential bug on asFunctionAndCall()

19 views
Skip to first unread message

Kris

unread,
Jun 22, 2011, 5:08:29 PM6/22/11
to mockit...@googlegroups.com
I'll take a look. Might be a bug.

Regards,
Kris

Kris

unread,
Jun 22, 2011, 5:08:01 PM6/22/11
to mockit...@googlegroups.com

papayavsbanana

unread,
Jun 22, 2011, 11:30:14 AM6/22/11
to mockito-flex
We are using mockito-1.4M3 and FlexUnit4.

We are testing a class and mock the service in it. We are unable to
pass parameter to a function called by mock object. This is what the
code is like (with non-important code stripped out):

public class Controller {
private var service:RemoteService;

public function action():void {
service.requestData(controllerCallback);
}

private function controllerCallback(data:String):void {
}
}

[Mock(type="com.data.services.RemoteService")]
public class ControllerTest {
private var controller:Controller;
private var service:RemoteService;

[Test]
public function shouldProcessDataFromService():void {
service = mock(RemoteService);

given(service.requestData(any())).will(useArgument(0)).asFunctionAndCall("Hello");

controller = new Controller(service);
controller.action();
}
}

The problem is on the "asFunctionAndCall". When running this, mockito
throws an error "While evaluating argument 0 failed ... : Expected 1,
actual 0."
When we make the controllerCallback's data an optional argument
(controllerCallback(data:String = 1)), there is no error, but of
course that is not what we want.


We even tried the sample test in the library. The original test works,
but the verification is somewhat invalid.

public class TestStubbing
{
[Mock(type="org.mockito.MockieClass")]
public var mockie:MockieClass;

[Test]
public function
testWillAllowCallingArgumentsAsFunctionsWithArgs():void
{
var arg:Object = {};

given(mockie.asyncWithCallback(any())).will(useArgument(0).asFunctionAndCall(arg));

mockie.asyncWithCallback(callbackFunction);

assertEquals(1, counter);
assertTrue(latestArgs.indexOf(arg) == 0);
}

public function callbackFunction(...args):void
{
counter++;
latestArgs = args;
}
}
First, callbackFunction takes optional argument, so there is no error
there. Second, the passed in arg array is an empty array, which is the
default value of "...args" when there is no argument passed in; thus
the assertion of latestArgs is not useful.
We modified arg to a string of "Hello" and check if latestArgs
contains it -- the answer is no.

Anybody seen this issue? I cannot seem to find any report about this
problem. Did I not use it correctly, or is there a bug?
Thank you!
Reply all
Reply to author
Forward
0 new messages