Java 为什么我的杜松子酒工厂总是返回空值?

Java 为什么我的杜松子酒工厂总是返回空值?,java,gwt,mockito,gwt-gin,jukito,Java,Gwt,Mockito,Gwt Gin,Jukito,我正在尝试编写一个使用我创建的杜松子酒工厂的Jukito测试 我的工厂看起来是这样的: public interface ClientFactory { public DOMModel create(Entity ref); } public class DOMModel { ... @Inject public DOMModel(CollabClientFactory collabFactory, @Assisted Entity ref, @Assisted Doc

我正在尝试编写一个使用我创建的杜松子酒工厂的Jukito测试

我的工厂看起来是这样的:

public interface ClientFactory {

    public DOMModel create(Entity ref);

}
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);
    }

    ...
}
我将其绑定到我的gin模块中,如下所示:

public class ClientModule extends AbstractGinModule {

    @Override
    protected void configure() {

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

    }

}
DOMModel看起来是这样的:

public interface ClientFactory {

    public DOMModel create(Entity ref);

}
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);
    }

    ...
}
然后我的测试如下所示:

@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);
    }

}

此测试失败,因为
model1
为空,但我没有收到任何其他错误或警告。怎么了?

你能发布DOMModel吗?代码是否在开发模式下干净地编译并运行?谢谢你的回复。是的,这将干净地编译,并且也将在开发模式下运行。我更新了DOMModel的示例代码。Cheers注意:CollabClientFactory也已正确绑定。为了简化,我只是在原始代码中省略了它,所以我最终创建了一个非常简单的测试来复制它,我发现了一些有趣的东西。如果我没有正确设置我的工厂,那么Jukito会为我模拟它,我想这就是为什么我从create中得到一个空值。我想,不知何故,朱基托不能给我一个工厂的真实版本(因为一些错误被压制),而是回到嘲笑。然而,如果我不能得到任何错误输出,我不知道如何去追踪它。所以这就是问题所在。我最终通过手动遍历所有代码并查看Jukito何时为我创建了一个mock,而不是该类的具体实现,从而使测试工作正常。然后我查看了所有这些类的依赖关系,并确保它们可以被正确地注入。非常麻烦,但这是我唯一能想到的抑制错误输出的方法。