This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Testing and the fly likes easymock with Spring mvc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "easymock with Spring mvc" Watch "easymock with Spring mvc" New topic

easymock with Spring mvc

Manon Baratt
Ranch Hand

Joined: Jan 30, 2006
Posts: 58

I am using easymock to test the controller in my Spring project. I am getting an object back (obj1) which is of the same type as obj but none of its properties are set. Here is the partial code:

controller= new ObjController();
objService= org.easymock.EasyMock.createNiceMock(objService.class);

obj1 = (Obj) controller.create(obj);

My service create method:

public @ResponseBody
Obj create(@ModelAttribute("object") Obj obj) {
return objService.saveObj(obj);

Any ideas why I am not getting the obj1 set?

enric jaen

Joined: Oct 15, 2010
Posts: 27

what does obj1 references at this moment?

If you want that saveObject return this: obj1 = (Obj) controller.create(obj);

then i think you should move the line here:

Manon Baratt
Ranch Hand

Joined: Jan 30, 2006
Posts: 58
Thanks for your reply. I got it working by using the same object since I am saving the object, I shall get the same object.

obj1 = (Obj) controller.create(obj);

obj1 is used in an assert statement in my code.

Thanks again
wood burning stoves
subject: easymock with Spring mvc
It's not a secret anymore!