On 16 January 2013 15:35, <capable2_at_gmail.com> wrote:
> Hi,
>
> I'm trying to test one of my Jersey Services. This particular Jersey
> Service I've written grabs an attribute out of the HttpSession object
> of the HttpServletRequest like so:
>
> HttpSession session =
> ((HttpServletRequest)httpRequest).getSession();
> userId = (UserId)
> session.getAttribute(USER_KEY);
>
> I'm wondering how to mock these values in my JerseyTest so that my
> service gets my mocked HttpServletRequest? Here's the code in my test,
> but I have no idea how to tell Jersey to use my mocked
> HttpServletRequest and HttpSession objects. Can someone throw me a
> bone?
>
This might not help you, but have you considered ways of testing this
code without having to mock objects that you don't own? By mocking a
third-party type, you can too easily make a test pass by making
expectations on what you /think/ the type does, not what it actually
does.