You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Mats Henricson <ma...@henricson.se> on 2009/09/04 14:36:17 UTC
Testify NullPointerException?
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
Re: Testify NullPointerException?
Posted by Angelo Chen <an...@yahoo.com.hk>.
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