Getting started doesn't have any tests?

49 views
Skip to first unread message

boz

unread,
Feb 9, 2011, 3:15:38 AM2/9/11
to GWTP
Hi,

Why doesn't the getting started (and the sample apps) have any JUnit
tests on presenters? Being able to test without GWT compile is a big
part of why I'm interested in MVP frameworks like GWTP, so it seems
weird to not have any in the examples. Am I missing something?

thanks,
boz

boz

unread,
Feb 9, 2011, 5:22:10 AM2/9/11
to GWTP
I've now gone through the basic getting started exercise. The page
displays and I was even able to add a CellTable to the View. Thanks
for the nice intro!

But I'm still at a loss for how to JUnit test the presenter. I created
a test that gets the view and sets the text on the name field. Like
this...
<code>
public class MainPagePresenterTest {

@Test
public void xxx() throws Exception {
Mockery context = new Mockery() {{
setImposteriser(ClassImposteriser.INSTANCE);
}};
EventBus eventBus = context.mock(EventBus.class);
MainPagePresenter.MyView view =
context.mock(MainPagePresenter.MyView.class);
MainPagePresenter.MyProxy proxy =
context.mock(MainPagePresenter.MyProxy.class);

MainPagePresenter cut = new MainPagePresenter(eventBus, view,
proxy);
cut.getView().getNameField().setText("foo");
assertEquals("foo", cut.getView().getNameField().getText());
}

}
</code>

It uses JUnit4 and JMock.

The test fails on the line where the mock is created for
MainPagePresenter.MyView.class because GWTP's View has a dependency to
com.google.gwt.user.client.ui.Widget which is a UIObject which causes
GWT.create() to be invoked. How do I make it so I can test without
invoking GWT.create()?

thanks,
boz

Christian Goudreau

unread,
Feb 9, 2011, 8:20:54 AM2/9/11
to gwt-pl...@googlegroups.com
Well, it's because you reference directly TextBox istead of HasText inside the view definition.

You shoudn't have any UiObject inside the view definition, else you will need to disarm Gwt.

I invite you to read this test:

and this blog entry:

Cheers,
--
Christian Goudreau

boz

unread,
Feb 9, 2011, 12:02:54 PM2/9/11
to GWTP
I should have included my view interface...
<code>
public interface MyView extends View {
HasText getNameField();
}
</code>

The "extends View" leads to the UiObject dependency.
- View.asWidget() returns Widget
- Widget extends UIObject

I'll read those links too though.
Thanks!
,boz

On Feb 9, 5:20 am, Christian Goudreau <goudreau.christ...@gmail.com>
wrote:
> Well, it's because you reference directly TextBox istead of HasText inside
> the view definition.
>
> You shoudn't have any UiObject inside the view definition, else you will
> need to disarm Gwt.
>
> I invite you to read this test:http://code.google.com/p/arcbees-hive/source/browse/test/com/arcbees/...
>
> <http://code.google.com/p/arcbees-hive/source/browse/test/com/arcbees/...>and
> this blog entry:http://arcbees.wordpress.com/2010/11/25/testing-views-using-gwt-platf...
>
> <http://arcbees.wordpress.com/2010/11/25/testing-views-using-gwt-platf...>

Christian Goudreau

unread,
Feb 9, 2011, 12:15:47 PM2/9/11
to gwt-pl...@googlegroups.com
View.asWidget() returns Widget
Well yes, but if you isolate your testing environment correctly, that function should never be called inside the presenter, if it is, think about GWT disarm() or maybe reworking the logic when you can.

Cheers, 
--
Christian Goudreau

Christofer Jennings

unread,
Feb 11, 2011, 4:36:52 AM2/11/11
to gwt-pl...@googlegroups.com
I've set up a project based on Hive and almost have it running, but I'm getting errors like this...
...
com.google.inject.CreationException: Guice creation errors:
1) No implementation for javax.inject.Provider<com.google.gwt.inject.rebind.binding.AsyncProviderBinding> was bound.
  while locating javax.inject.Provider<com.google.gwt.inject.rebind.binding.AsyncProviderBinding>
    for parameter 9 at com.google.gwt.inject.rebind.BindingsProcessor.<init>(BindingsProcessor.java:210)
  at com.google.gwt.inject.rebind.GinjectorGeneratorModule.configure(GinjectorGeneratorModule.java:59)
...

It seems to be a GIN related conflict. I see there are some snapshot jars in the Hive project. Are these jars compatible? (from my WEB-INF/lib)
   aopalliance.jar
   gin-1.0.jar
   gin-r152.jar
   guice-2.0.jar
   guice-assistedinject-2.0.jar
   guice-servlet-2.0.jar
   gwt-servlet.jar
   gwtp-all-0.5.jar
   javax.inject.jar

The Hive code is very nice to read, by the way. It's a lot for me to absorb, though, since I'm new to guice, gin & gwt-presenter. But I'm learning.

thanks!
boz

Christian Goudreau

unread,
Feb 11, 2011, 9:45:35 AM2/11/11
to gwt-pl...@googlegroups.com
r152 and guice 2 aren't the one used.

I'm using Guice 3 - mc2  and latest Gin from repository for assisted injection. Don't you have those jar when you pull the projet ?

Btw we will be converting this project to maven soon.

Cheers,
--
Christian Goudreau
Reply all
Reply to author
Forward
0 new messages