Announcement Announcement Module
No announcement yet.
NPE in AnnotationMethodHandlerAdapter in unit tests of Controllers Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • NPE in AnnotationMethodHandlerAdapter in unit tests of Controllers

    Hi there,

    I have just updated to Spring 3.1 and got some NPEs in my controllers tests (stacktrace below).

    In my workaround, I just set the needed request attribute as the DefaultAnnotationHandlerMapping would do in my preconditions for the test, because I use some code like

    //setup preconditions
    ModelAndView mv = new AnnotationMethodHandlerAdapter().handle(request, response, controller);
    //do the asserts with the model and view

    so my question:
    Is there a better/other way to test controllers or should the AnnotationMethodHandlerAdapter be more robust to handle request without this attribute??

    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter$ServletHandlerMethodRe solver.useTypeLevelMapping(AnnotationMethodHandler
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter$ServletHandlerMethodRe solver.resolveHandlerMethod(AnnotationMethodHandle
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho

  • #2
    There is a better way to test controllers. See this project. If you're on Spring 3.1, unless you have some specific reason not to do that, I recommend switching to the new RequestMappingHandlerAdapter, RequestMappingHandlerMapping, and ExceptionHandlerExceptionResolver. See the what's new section in the 3.1 reference docs.