Question

I've recently introduced Guice into my ActionBeans, where previously the actionbean had its data access layer implementation hardcoded.

I have an integration test like this:

MockServletContext context = TestHelper.getServletContext();
MockRoundtrip trip = new MockRoundtrip(context, LoginActionBean.class);


trip.setParameter("authenticate", "Login");
trip.setParameter("username", "testuser2");
trip.setParameter("password", "testuser2pass");
trip.setParameter("targetUrl", "Activity.action?jobId=1");
trip.execute();

LoginActionBean bean = trip.getActionBean(LoginActionBean.class);

Now that I'm using Guice, I can't find a way to inject the dependencies into the LoginActionBean, since I never actually instantiate it myself.

How can I tell guice to inject the dependencies into this class?

Was it helpful?

Solution

You will need to configure the MockServletContext with a Guice configuration, like you have in your web.xml (probably in your TestHelper class getServletContext() method).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top