Friday, September 2, 2011

Re: Unit testing classes that depends on RequestFactory

I came with an thin abstraction layer over request factory. My presenter declare an inner interface called DataService which exposes methods from RF that are needed for that presenter. For exemple:

public class PesquisaPresenter {
public interface DataService {
void findById(long id, Receiver<PesquisaProxy> receiver);
}
}

The presenter receives an instance of it's DataService through constructor injection, and the implementation of the service is as simple as:
public class PesquisaPresenterDataServiceImpl implements PesquisaPresenter.DataService {

private final RequestFactory requestFactory;

@Inject public PesquisaPresenterDataServiceImpl(RequestFactory requestFactory) {
this.requestFactory = requestFactory;
}

@Override
public void findById(long id, Receiver<PesquisaProxy> receiver) {
requestFactory.pesquisaRequest().findById(id).with("relatorios").fire(receiver);
}
}

When testing the presenter, I have now only one interface to mock. So far it seems to fit my needs


On Thu, Sep 1, 2011 at 2:29 PM, Magno Machado <magnomp@gmail.com> wrote:
How are you guys dealing with unit tests of classes that uses request factory?

I started mocking the requestfactory and requestcontexts interfaces, but I'm not satisfied with this because it requires a lot of code just to set up things

I searched a bit and found RequestFactorySource class, which create implementations of RequestFactory to run on the JVM. I thought about using it with a service layer decorator that return mocks on the createServiceInstance() method. The mocks would be created and controlled by Mockito




--
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 google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment