0

I am trying to write a Jukito test that uses a GIN factory I created.

My factory looks like so:

public interface ClientFactory {

    public DOMModel create(Entity ref);

}

I am binding it in my gin module like so:

public class ClientModule extends AbstractGinModule {

    @Override
    protected void configure() {

        install(new GinFactoryModuleBuilder().build(ClientFactory.class));

    }

}

DOMModel looks like so:

public class DOMModel {

    ...

@Inject
public DOMModel(CollabClientFactory collabFactory, @Assisted Entity ref, @Assisted Document domDoc){
    this.colabClient = collabFactory.create("DOMMODEL:"+ref.getID(), "com.server.impl.DOMCollabSite.java", collaborator);
    }

    ...
}

Then my test looks like this:

@RunWith(JukitoRunner.class)
public class Test {

  public static class Module extends JukitoModule {
    protected void configureTest() {

        install(new GinModuleAdapter(new ClientModule()));

    }
  }

  @Inject
  ClientFactory modelFactory;

  @Test
  public void testSimple() throws Exception{
       Entity entity = new Entity(){
            @Override
            public String getID() {

             return "someID";
            }
       };

       DOMModel model1 = modelFactory.create(entity);

         assertNotNull(model1);
    }

}

This test fails because model1 is null, however I get no other errors or warnings whatsoever. What is wrong?

durron597
  • 31,968
  • 17
  • 99
  • 158
Casey Jordan
  • 1,204
  • 1
  • 20
  • 39
  • Can you post DOMModel? Does the code compile cleanly as well as running in dev mode? – Colin Alworth Mar 19 '14 at 03:42
  • Thanks for the reply. Yes this compiles cleanly and will also run in dev mode. I updated with sample code for DOMModel. Cheers – Casey Jordan Mar 19 '14 at 17:35
  • Note: The CollabClientFactory is also bound correctly. I just had it omitted from the original code for simplification. – Casey Jordan Mar 19 '14 at 18:30
  • So I ended up creating a very simple test to replicate this and I found something interesting. If I do not correctly setup my factory, then Jukito mocks it for me, and I think that is why I am getting a null value from the create. I think somehow Jukito is not able to give me a real version of the factory (because of some errors which are being supressed) and instead falls back to mocking. However I have no idea how to go about tracking this down if I can't get any error output. – Casey Jordan Mar 19 '14 at 18:39
  • So that turned out to be the problem. I finally got the tests working by manually walking down through all the code and looking at when Jukito created a mock for me instead of a concrete implementation of that class. Then I looked at all of that classes dependencies and made sure they could be injected properly. Very cumbersome but it's the only thing I could think of with the error output supressed. – Casey Jordan Mar 20 '14 at 14:35

0 Answers0