• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

easymock with Spring mvc

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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);
controller.setObjService(objService);

expect(objService.saveObj(obj)).andReturn(obj1);
replay(objService);
obj1 = (Obj) controller.create(obj);

My service create method:

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

Any ideas why I am not getting the obj1 set?

Thanks!!
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

expect(objService.saveObj(obj)).andReturn(obj);
replay(objService);
obj1 = (Obj) controller.create(obj);

obj1 is used in an assert statement in my code.

Thanks again
 
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic