Hi, I'm writing Junittest cases for my servlets. I am using Mockito.mock to mock the request and response object. But when I'm creating session object from the mocked request object the value is coming as null. Please let me know how can I get a session object mocked.
This can be a symptom (code smell) that you're loading up your controller with too much logic/responsibility. You should be able to test your core logic without having to depend on the fact that the input values are coming in from an HTTP request. HTTP is a delivery mechanism, an implementation detail. Your core business logic should not be dependent on it. All it should care about is that it does get some values somehow. That's the level at which you should do unit testing. If you're trying to unit test your controller class, then you should go with Matthew's suggestion but apart from that, you probably should look at refactoring your controller class and pushing some responsibilities down to the business layer classes.