Not able to use install in test class

45 views
Skip to first unread message

Soubhratra Das

unread,
Aug 27, 2012, 5:00:52 PM8/27/12
to juk...@googlegroups.com
Hi all,
I have starting up with GWTP and Jukito. I am getting compilation error while trying to use install(new clientModule()) in my test class. Below is the code fragment..please suggest what is wrong here. Thanks in advance.

@RunWith(JukitoRunner.class)
public class MainPagePresenterTest extends XXXBasePresenterTest {

/**
  * Guice test module.
  */
public static class Module extends XXXBaseTestModule {
   @Override
   protected void configurePresenterTest() {
                install(new ClientModule());

    forceMock(ObjectCommandOptionsPopupPresenter.class);
   }
}
 
// SUT
@Inject
MainPagePresenter presenter;
@Inject 
MainPagePresenter.MyView view;

.............
}

public abstract class XXXBaseTestModule extends JukitoModule {

@Override
protected void configureTest() {
 
configurePresenterTest();
}
protected abstract void configurePresenterTest();
}

public class ClientModule extends AbstractPresenterModule {
@Override
protected void configure() {
// Default implementation of standard resources
install(new DefaultModule(xxxPlaceManager.class));
....... 
//Other bindings

   }

Getting the following error - 

Caused by: java.lang.ClassCastException: com.xxx.xxx.webapp5.client.gin.ClientModule cannot be cast to com.google.inject.Module
        at com.xxx.xxx.webapp5.XXXBaseTestModule.configureTest(XXXBaseTestModule.java:13)

Thanks,
SD


Christian Goudreau

unread,
Aug 28, 2012, 10:33:51 AM8/28/12
to juk...@googlegroups.com
What is the code for ClientModule?
--
Christian Goudreau

Soubhratra Das

unread,
Aug 28, 2012, 11:42:10 AM8/28/12
to juk...@googlegroups.com
I provided the snippet in the original mail but possibly lost in other code. Here it is -

public class ClientModule extends AbstractPresenterModule {
@Override
protected void configure() {
// Default implementation of standard resources
install(new DefaultModule(DbvsPlaceManager.class));

// Constants
bindConstant().annotatedWith(DefaultPlace.class).to(
NameTokens.contentPage);

..............//Other bindings....
}

Thanks,
SD

Christian Goudreau

unread,
Aug 29, 2012, 11:39:14 AM8/29/12
to juk...@googlegroups.com
And the other bindings? :D

At first it's weird, but maybe there's a binding that involve "client side code" that isn't compatible with JUnit.

What I suggest you do is to only bind manually what you need for that one test and not the whole module itself.

Cheers,
--
Christian Goudreau

Stephan Classen

unread,
Aug 29, 2012, 4:16:35 PM8/29/12
to juk...@googlegroups.com
I think the problem has nothing to do with guice or jukito.

First of all, Just to make sure: you get a ClassCastException and not a compilation error. Because those are two different things.
So if I'm wrong and you do get a compilation error (when you are compiling your project and not while running the test) please correct me.

If you get the following ClassCastException

java.lang.ClassCastException: com.xxx.xxx.webapp5.client.gin.ClientModule cannot be cast to com.google.inject.Module
        at com.xxx.xxx.webapp5.XXXBaseTestModule.configureTest(XXXBaseTestModule.java:13)

It means that com.xxx.xxx.webapp5.client.gin.ClientModule is not a child class com.google.inject.Module.
Now I don't have your entire Object hierarchy. But I suggest you do the following:
1) make sure ClientModule implements com.google.inject.Module
2) If 1) is true it is most likely a problem with your path. make sure that the jars which are used at compile time are the same as the ones used at runtime.

Greets Stephan
Reply all
Reply to author
Forward
0 new messages