You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2009/10/22 17:48:05 UTC

Re: Testify NullPointerException?

hi,
I have similar problem, did you find a solution? Thanks.

Mats Henricson-2 wrote:
> 
> Hi!
> 
> I'm getting pretty close now. I've managed to get to the
> renderPage() function, where I get a NPE:
> 
> Caused by: java.lang.NullPointerException
> 	at
> org.apache.tapestry5.internal.renderers.RequestRenderer.render(RequestRenderer.java:48)
> 
> What happens on that line is:
> 
>     String contextPath = request.getContextPath();
> 
>     if (contextPath.equals(""))    // This is line 48
> 
> What happens in RequestImpl (I assume that is the class used here)
> is a delagation to the HttpServletRequest:
> 
>     return request.getContextPath();
> 
> And I've mocked this HttpServletRequest in my Module like this:
> 
> public static void
>    contributeRequestHandler(OrderedConfiguration<RequestFilter> config,
>                             final RequestGlobals requestGlobals) {
>     RequestFilter filter = new RequestFilter() {
>         public boolean service(Request request,
>                                Response response,
>                                RequestHandler handler)
>                 throws IOException {
> 
>             HttpServletRequest  httpServletRequest  =
>                mock(HttpServletRequest.class);
>             HttpServletResponse httpServletResponse =
>                mock(HttpServletResponse.class);
> 
>             when(httpServletRequest.getContextPath()).thenReturn("");
> 
>             requestGlobals.storeServletRequestResponse(
>                             httpServletRequest, httpServletResponse);
> 
>             return handler.service(request, response);
>         }
>     };
>     config.add("EnsureNonNullHttpRequestAndResponse",
>                filter, "before:*");
> }
> 
> As you can see, I've mocked HttpServletRequest to return "" if
> getContextPath() is called, so how can I get a NPE?
> 
> Mats
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Testify-NullPointerException--tp25293589p26012428.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org