In general you should dependency inject it, using constructor injection or
method injection. Field injection is only a good idea in code that you don't
need to test. I would image that JAX-RS does more than just field injection?
If that doesn't work, you could add a constructor and make it package
private. Or create a builder using a library that makes it easy (shameless
self-promotion: http://tinyurl.com/builderbuilder).

Robbie

On Sun, Oct 26, 2008 at 9:52 PM, Gili <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I've got code that runs on top of JAX-RS and Guice. All my classes use
> construction injection. One such class has the following field:
>
> @Context UriInfo uri;
>
> that is injected after-the-fact by JAX-RS.
>
> When I try unit testing this code I run into a problem because I'm not
> sure how to inject a mock object in place of "uri". Guice isn't
> injecting it in the first place. I was thinking of adding UriInfo to
> the constructor and making it optional but Guice doesn't support that
> sort of thing. Alternatively I could add a setUri() method to be used
> exclusively by the test framework but this seems a bit ugly.
>
> I'm new to unit testing. I would appreciate some advice.
>
> Thank you,
> Gili
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to