On 10 sep, 00:30, Ben <benzhe...@gmail.com> wrote:
> Hi, I am using MVP architecture for my application, but I am trying to
> use EasyMock to provide mock objects to test all my presenters. I have
> a question about testing event handlers from GWT such as ClickHandler.
> Does anyone try to use EasyMock to test click event? Or I should write
> my own mock event and mock handler like it is mentioned in GWT blog.

Here's an adapted excerpt from my code:

MyPresenter.Display view = createMock(MyPresenter.Display.class);
HasClickHandlers button = createMock(HasClickHandlers.class);
expect(view.getSomeButton()).andStubReturn(button);

Capture<ClickHandler> clickHandler = new Capture<ClickHandler>();
HandlerRegistration clickRegistration = createNiceMock
(HandlerRegistration.class);
expect(button.addClickHandler(capture(clickHandler))).andReturn
(clickRegistration);

replay(view, button, clickRegistration);

new MyPresenter(view);

clickHandler.getValue().onClick(null);

verify(view, button, clickRegistration);


Here, I'm expecting a single ClickHandler to be registered on the
view's getSomeButton() (afaict, from memory, the sample "hand-written
mock" from Ray's preso behaves the same), and one that doesn't make
use of the ClickEvent (if that's not your case, you can use
org.easymock.classextension.createMock(ClickEvent.class) and some
expect(clickEvent.getSource()).andStubReturn(button).


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

Reply via email to