Thursday, September 1, 2011

Re: How to mock Listbox when testing the Presenter class?

I'd highly encourage you to use the pattern from the "MVP - part 2" article from the GWT doc, where the presenter itself implements an interface that the view calls back, rather than exposing the view through HasXxxHandlers and the like. It makes mocking so much painful! (having to mock HasXxxHandlers is a PITA compared to simply mocking your View interface, and capturing the presenter from the setPresenter method so you can call methods on it as if the view did it).

To answer your question, your view should expose the methods you use from the ListBox (and simply delegate them to the listbox); you shouldn't try to expose "the listbox" as an object from your view (because as you said, there's no "matching" interface). So you'll add those 7 methods to your view (possibly using a naming scheme such as getAdmin, setAdmin, etc.).
Also, instead of a ListBox, you could use a ValueListBox so you can directly "push" your "model" to your view, and get the selected object back from the view.

--
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/-/42fOfcKwQ6YJ.
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