users@jersey.java.net

[Jersey] Re: Mocking objects for Jersey unit tests

From: Jason Erickson <jason_at_jasonerickson.com>
Date: Wed, 12 Oct 2011 17:35:59 -0700

I think you could use ReflectionTestUtils if you're using Spring. It's just a utility class that lets you set private fields to values (mocks in your case).

http://static.springsource.org/spring/docs/2.5.5/api/org/springframework/test/util/ReflectionTestUtils.html

On Oct 12, 2011, at 6:41 AM, matthew huckaby wrote:

> Can anyone share an example as to how to mock fields on resources during a Jersey unit test using Grizzly web container?
> The problem is basically that because Jersey instantiates the resource to handle the REST request - any dependencies inside the
> resource class are null.
>
> In a non-test runtime I am using Spring coupled with the com.sun.jersey.spi.spring.container.servlet.SpringServlet to wire beans etc.
>
> Thank you,
> Matthew Huckaby