Hi,
I am using annotations to create a controller method which accepts a string and returns a ModelAndView object that contains the response object and the view.
The controller goes something like this.
Code:@Controller @RequestMapping("/abc/(*:xyz)") public class MyController { private final Log log = LogFactory.getLog(getClass()); @Autowired(required = true) private MyProxy myProxy; @RequestMapping(method = RequestMethod.GET) @SuppressWarnings("unchecked") public ModelAndView getMyData(@RequestParam(required = false, value = "xyz") String myStr) { MyObject myObject= null; if (myProxy!= null) { myObject= myProxy.getProxyData(myStr); } return new ModelAndView("myView", "myData", myObject); } }
Now, when I am testing this controller, I am getting a null pointer exception when i call the getMyData() method on the controller. Why isnt my controller object being created ?
The test class is this :
Code:public class TestMyClass extends TestCase { private MyController controller; @Before public void setup() { controller = new MyController (); } @Test public void testMyData() { assertEquals("myView", controller.getMyData("83765876")); } }


Reply With Quote
.
