I use this code to test classes that depends on requestfactory (the same
idea applies to gwt-rpc as well):
public static class RequestFactoryUtils {
 public static Stubber doSuccess(final Object result) {
return Mockito.doAnswer(new Answer<Object>() {

@Override
public Object answer(InvocationOnMock invocation)
throws Throwable {
Object[] args = invocation.getArguments();
Receiver<Object> receiver = (Receiver<Object>) args[args.length - 1];
receiver.onSuccess(result);
return null;
}
 });
}
        }

......

import static RequestFactoryUtils.*;

@Test
public void testSomething() {
    MyService service = mock(MyService.class);
    doSuccess(new Foo("Bar")).when(service).getFoo(any(Receiver.class));
}

Of course this doesn't exercise the server implementation.

For void methods, you should test it's side effects

On Tue, Sep 6, 2011 at 2:22 PM, BM <[email protected]> wrote:

>  In Junit I am trying to test the method  which is not returning
> anything using the Mockito, but I am not able to test it.
> ==> You would need to understand what this method with return type
> void is actually doing. If it is updating some class level variables
> then you can assert on those variables. If you are manipulating some
> objects passed into its method signature then you may need to assert
> on the expected values of the method signature variables.
>
>  In Junit, If I am trying to test the asynchronous calls in GWT
> ==> I don't think it is necessary to JUnit test RPC calls as long as
> you are JUnit testing the backend services separately. RPC calls are
> asynchronous in nature and require GWT.create statement for Async
> proxy handle and that will only run under GWT container. Using mockito
> you can ask to handle GWT.create but what mockito really doing is
> really faking it as if the RPC call was successful (it doesn't make
> RPC call) which doesn't make sense to begin with to test it an RPC
> call.
>
> If you really want to just test all your RPC calls then you would need
> to test those methods under GWTTestcases separately and put a delay
> timer [delayTestFinish(TIME_TO_WAIT)] that way the test class can wait
> for the callback function. OnSuccess method will have an assertion and
> finishTest() method call. OnFailure will have fail("Failed on
> something :" + caught.getMessage()) method.
>
>
>
> On Sep 6, 8:59 am, Anuj Garg <[email protected]> wrote:
> > Hi All,
> >
> > 1. In Junit I am trying to test the method  which is not returning
> > anything using the Mockito, but I am not able to test it.
> >
> > 2. In Junit, If I am trying to test the asynchronous calls in GWT
> > using Mockito, then I am not understanding how to do it, because
> > synchronous method gives the result in onSuccess() / onFailure()
> > methods.
> >
> > Please help, If anybody has an idea how to do the testing of these
> > kind of methods using Mockito.
> >
> > It would be a great help, If you will provide any help.
> >
> > Thanks and Regards,
> > Anuj Kumar,
> > Noida,
> > India
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>


-- 
Magno Machado Paulo
http://blog.magnomachado.com.br
http://code.google.com/p/emballo/

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to