users@jersey.java.net

Re: [Jersey] creating UriInfo in unittests

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 30 Apr 2010 10:53:45 +0200

On Apr 29, 2010, at 8:28 AM, tarjei wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 04/28/2010 10:14 PM, Beatriz Nombela wrote:
>> Hi,
>>
>> In my unit tests I use to mock that kind of objects injected in
>> runtime, like UriInfo or SecurityContext. I simulate them with
>> mockito
>> framework (http://mockito.org/).
> Yes, I also used to be a fan of mocks, but with Java I find that they
> create too much boilerplate code so I try to avoid them as much as
> possible.
>
> Still, if nothing else fits, I guess I'll have to create mocks. Any
> other ideas?
>

Run tests using an embedded container, like grizzly. Then Jersey will
do the creation and injection.

See for example:

   http://download.java.net/maven/2/com/sun/jersey/samples/helloworld-webapp/1.1.5.1/helloworld-webapp-1.1.5.1-project.zip

Paul.