Better Software - November 2008 - (Page 31) public class MeetingViewWidget extends Composite implements MeetingView { private Button saveButton = new Button(“Save”); private TextBox capacityText = new TextBox(); public MeetingViewWidget() { VerticalPanel mainPanel = new VerticalPanel(); HorizontalPanel row = new HorizontalPanel(); row.add(new Label(“Capacity:”)); row.add(capacityText); mainPanel.add(row); mainPanel.add(saveButton); // Start with the save button disabled saveButton.setEnabled(false); // Here the view is responsible for creating the model and presenter final Presenter presenter = new Presenter(new Meeting(), this, new RemoteRoomScheduler()); capacityText.addChangeListener(new ChangeListener() { public void onChange(Widget sender) { presenter.requiredCapacityChanged((HasText) sender); } }); initWidget(mainPanel); } public void disableSaveButton() { saveButton.setEnabled(false); } } Listing 7 public AlternatePresenter(Meeting meeting, MeetingView meetingView, RoomScheduler roomScheduler) { this.meeting = meeting; this.meetingView = meetingView; this.roomScheduler = roomScheduler; // Register to receive all widget callbacks to this presenter meetingView.registerPresenter(this); } Listing 8 Note here that the view is instantiating the model and presenter objects, which is one way of ensuring that the presenter is instantiated with a “live” view. You also could have some higherlevel application object construct the view and pass it to the presenter, which would then need to register itself with the view so all the controls know where to send their events. This would look something like listing 8. uring the display widgets. So how do we test it in a GWTTestCase? We don’t. In fact, there’s not much here that can be tested in an automated test. As stated earlier, event propagation won’t work by default in a GWTTestCase, and the layout of widgets is often best checked visually. If you are building a widget library, then you might want to write GWTTestCases that test the widget through its API, which is what Google does with the widgets included in GWT, such as Button, TextBox, and Tree. However, these tests are slow (a sample widget test takes twelve seconds on my two-year-old workstation), and any complex logic could be moved into a simple presenter object, which could be tested in a plain old, fast JUnit TestCase. For more ideas for testing GWT widgets, see the StickyNotes for a link to my blog post on the subject. www.StickyMinds.com testing asynchronous access to Remote services GWT provides a remote procedure call (RPC) mechanism that enables passing Java objects between the server and client using a server-side serialization library. GWTTestCase supports testing of these features by providing utility methods that facilitate writing asynchronous tests. Most of the inforNOVEMBER 2008 BETTER SOFTWARE 31 http://www.StickyMinds.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.