Results 1 to 2 of 2

Thread: NPE in AnnotationMethodHandlerAdapter in unit tests of Controllers

  1. #1
    Join Date
    Jun 2007
    Location
    Berlin, Germany
    Posts
    20

    Default 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. #2
    Join Date
    Aug 2006
    Location
    Brooklyn
    Posts
    556

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •