Button.click() not working

0 views
Skip to first unread message

Josué

unread,
May 31, 2009, 8:43:13 PM5/31/09
to Google Web Toolkit
Hello All,

The following code is not throwing a RuntimeException. Someone here
know why?

button = new Button("button");

button.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event) {
throw new RuntimeException(".onClick() not implemented");
}});

button.click();
...

My version of GWT is 1.6.4. The one that came with google eclipse
plugin for Eclipse.

Thanks for any help.

Ian Bambury

unread,
May 31, 2009, 10:12:08 PM5/31/09
to Google-We...@googlegroups.com
Because you haven't added it to the DOM?

Maybe GWT should throw an error if it's not attached, but it doesn't.

Josué

unread,
Jun 1, 2009, 7:09:13 PM6/1/09
to Google Web Toolkit
Thanks Ian. I see your great help to others here. You information
resolved the problem.

Explaining what I was trying to do to others, I am developing a GWT
view using the MVP pattern. It is because a I want to use as minimal
as possible GWTTestCase or GWTTestSuite. They are slow to start run.
So I prefer to use conventional JUnit tests whenever possible.

But there are cases where the only way to test is calling directly the
View. In that cases GWTTestCase and GWTestSuite come to rescue.

What I was trying to do is to ensure that when i click in a button in
the view, the expected delegation to presenter is done. Some code:

* * *
@Override
protected void gwtSetUp() throws Exception {
viewTask = new ViewTask(ObjectMother.getConstantsStub
());
RootPanel.get().add(viewTask);

};

public void
testClickOnInsertShouldCallPresenterPrepareTaskInsert() throws
Exception {
TaskPresenterMock presenterMock = new TaskPresenterMock
();
viewTask.setPresenter(presenterMock);
viewTarefa.insertButton.click();
assertTrue(presenterMock.isCalledPrepareTaskInsert());
}
* * *

The code that I was missing was this: RootPanel.get().add(viewTask);

For instance, the tests that use GWTTestCase and Suite I call slow
tests and run with less frequency.

Sorry my English,

Abraços,

Josué.




On May 31, 11:12 pm, Ian Bambury <ianbamb...@gmail.com> wrote:
> Because you haven't added it to the DOM?
> Maybe GWT should throw an error if it's not attached, but it doesn't.
>
> Ian
>
> http://examples.roughian.com
>
> 2009/6/1 Josué <josuesan...@gmail.com>
Reply all
Reply to author
Forward
0 new messages