Announcement Announcement Module
Collapse
No announcement yet.
NPE in AnnotationMethodHandlerAdapter in unit tests of Controllers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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

    Code:
    //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??



    java.lang.NullPointerException
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter$ServletHandlerMethodRe solver.useTypeLevelMapping(AnnotationMethodHandler Adapter.java:675)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter$ServletHandlerMethodRe solver.resolveHandlerMethod(AnnotationMethodHandle rAdapter.java:585)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:431)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:424)

  • #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.

    Comment

    Working...
    X