you can see gwt-dispatch <http://code.google.com/p/gwt-dispatch/> for command pattern.
2011/8/11 Miroslav Genov <[email protected]> > In my experience, using of mocking frameworks for testing of Async calls is > not so good and tests are becoming un-readable at some point of time. In our > app we are using Command Pattern to send different requests > (Action/Response) and here is our helper class that we are using for > testing: > > public class FakeRpcService implements RpcServiceAsync { > > public Action<?> lastAction; > public AsyncCallback<?> lastCallback; > > public <T extends Response> void execute(Action<T> action, > AsyncCallback<T> async) { > lastAction = action; > lastCallback = async; > } > > public <T> T lastAction() { > return (T) lastAction; > } > > public void responsesWith(Response response) { > // SMELL private members of simple object are referencing template > members? > ((AsyncCallback<Response>) lastCallback).onSuccess(response); > } > > public void failsWith(RuntimeException e) { > ((AsyncCallback<Response>) lastCallback).onFailure(e); > } > } > > so our tests now are looking like: > > @Test > public void exportSelectedInvoices() { > List<InvoiceDto> invoices = > Lists.newArrayList(createInvoice("1",PaymentType.CASH)); > > // filter button was clicked > presenter.onReportRequested(); > service.responsesWith(new GetInvoicesPeriodReportResponse(invoices)); > > presenter.onExportSelectedInvoices(new HashSet<InvoiceDto>()); > > GenerateAjurExportAction action = service.lastAction(); > assertThat("the one selected invoice was not sent for > export?",action.getInvoices(), is(equalTo(invoices))); > > service.responsesWith(new GenerateAjurExportResponse("test test")); > assertThat("export response was not > displayed?",display.exportResponse,is(equalTo("test test"))); > } > > Hope this will help you figure out what's the best choice for you. > > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/google-web-toolkit/-/OTxCnyHee14J. > > 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. > -- 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.
