我正在使用 Mockito 测试我的 GWTP 项目,但出现了一些错误:
com.google.inject.CreationException: Guice creation errors:
1) No implementation for javax.servlet.http.HttpServletRequest was bound.
while locating com.google.inject.Provider<javax.servlet.http.HttpServletRequest>
for parameter 0 at com.gwtplatform.dispatch.server.guice.request.DefaultRequestProvider.<init>(DefaultRequestProvider.java:35)
at com.gwtplatform.dispatch.server.guice.DispatchModule.configure(DispatchModule.java:135)
下面是单元测试的代码:
@Mock
private TestActionHandler mockTestActionHandler;
@Before
public void setUp() {
Injector injector = Guice.createInjector(new ServerModule(), new MockHandlerModule() {
@Override
protected void configureMockHandlers() {
bindMockActionHandler(TestActionHandler.class,
mockTestActionHandler);
}
});
}
下面是 TestActionHandler 的代码:
public class TestActionHandler implements ActionHandler<TestAction, TestResult> {
private final Provider<HttpServletRequest> provider;
@Inject
public RetrieveEventsUsingCategoryIdActionHandler(
final Provider<HttpServletRequest> provider) {
this.provider = provider;
}
@Override
public TestResult execute(TestAction action, ExecutionContext context) {
//handle action
}
}
谁能帮我解决这个问题?非常感谢!