I am trying to set up a test in JUnit w / EasyMock and I am having a small problem that I cannot wrap my head with. I was hoping someone here would help.
Here is a simplified version of the method I'm trying to test:
public void myMethod() { //(...) Obj myObj = this.service.getObj(param); if (myObj.getExtId() != null) { OtherObj otherObj = new OtherObj(); otherObj.setId(myObj.getExtId()); this.dao.insert(otherObj); } //(...) }
Ok, so with EasyMock I made fun of calling service.getObj(myObj) , and it works great.
My problem occurs when JUnit gets into the dao.insert(otherObj ) call. EasyMock drops *Unexpected Method Call* .
I would not mind mocking this dao in my test and use expectLastCall().once(); on it, but it assumes that I have a handle to "otherObj", which is passed as a parameter during insertion ... Which, of course, I do not, because it is conditionally created in the context of the method being tested.
Has anyone had to deal with this and somehow solve it?
Thanks.
methods junit easymock call
Lancelot
source share