I'm having some trouble getting my unittests to work when I use Guice to get an
instance of the HttpServletRequest object. The page works fine when running in
jetty, but in the unittests I get these errors.
org.apache.wicket.WicketRuntimeException: Can't instantiate page using
constructor 'public
com.hp.honeybadger.console.HomePage(org.apache.wicket.request.mapper.parameter.PageParameters)'
and argument ''. Might be it doesn't exist, may be it is not visible (public).
1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot
access scoped object. Either we are not currently inside an HTTP Servlet
request, or you may have forgotten to apply
com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
at
com.google.inject.servlet.InternalServletModule.provideHttpServletRequest(InternalServletModule.java:95)
while locating javax.servlet.http.HttpServletRequest
Caused by: com.google.inject.OutOfScopeException: Cannot access scoped object.
Either we are not currently inside an HTTP Servlet request, or you may have
forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter
for this request.
This is my page
public class HomePage extends WebPage {
private static final long serialVersionUID = 1L;
@Inject private HttpServletRequest request;
public HomePage(final PageParameters parameters) {
super(parameters);
add(new Label("version",
getApplication().getFrameworkSettings().getVersion()));
// TODO Add your page's components here
add(new Label("method", request.getMethod()));
}
}
QUESTION
How can I get around this issue or make use of a mock object to enable
unittests?