tags:

views:

23

answers:

2

I have a method that uses setAttribute on the Request object. I need to test that method to see if the attribute set has the right value. I am using EasyMocks and am new to it. I created a mock request object. But I need some help on how to test the method.
Thanks for any help

A: 

I would use Spring MockHttpServletRequest and MockHttpServletResponse classes.

http://www.jarvana.com/jarvana/view/org/springframework/spring/2.0.4/spring-2.0.4-javadoc.jar!/org/springframework/mock/web/MockHttpServletRequest.html

hvgotcodes
I am not using the Spring framework. I am working on the J2EE legacy framework.
Milee
then Peter Torok's answer is the way to go.
hvgotcodes
+1  A: 

Once you created the mock object, you can simply set it up by calling specific methods on it with the expected values. If it needs to return values, you use EasyMock.expect(...) to configure those. Once you are ready, you call EasyMock.replay(...) to start the testing phase. After the tests you should call EasyMock.verify(...) to check that all preconfigured calls have been made with the expected parameters.

See the documentation for more details and examples.

Péter Török
Thanks a lot. That helped.
Milee