Friday, September 2, 2011

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

I'm sorry I don't understand; the code from the article (and the "Activities and Places" page from the documentation) speaks for itself.

interface Presenter: defines methods called by the view (generally in response to user events)
interface View: defines methods called by the presenter to update the view + defines a setPresenter(Presenter) method.

class MyPresenter: implements the Presenter interface, receives a View in its constructor. At one point, calls the view.setPresenter(this) (if MyPresenter is an activity, you'd probably do that in the start() method; and I like calling view.setPresenter(null) in onStop and onCancel so it "cleans things up after itself")
class MyView: implements the View interface. When it needs to talk to the presenter, it uses the one previously set by a call to setPresenter.

MyPresenter doesn't know MyView, only View; and MyView doesn't know MyPresenter, only Presenter. But MyPresenter and MyView both have a reference to the other (through the View and Presenter interfaces; the View received in the Presenter's constructor, and the Presenter receivedin the View's setPresenter)

When you test MyPresenter, you mock View, and call methods from the implemented Presenter interface to simulate user actions on the view.

(note: this is how many people do; if you prefer injecting the presenter into the view, injecting it with a setter rather than the constructor, etc. feel free to do it the way you like it, the way feel comfortable with)

--
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/-/Vhhwz_24StAJ.
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