[ACCEPTED]-JUnit Easymock Unexpected method call-easymock
You could also use EasyMock.isA(OtherObj.class)
for a little more type 1 safety.
If you can't get a reference to the object 9 itself in your test code, you could use 8 EasyMock.anyObject()
as the expected argument to yourinsert
method. As 7 the name suggests, it will expect the method 6 to be called with.. well, any object :)
It's 5 maybe a little less rigorous than matching 4 the exact argument, but if you're happy 3 with it, give it a spin. Remember to include 2 the cast to OtherObj
when declaring the expected 1 method call.
The anyObject() matcher works great if you 7 just want to get past this call, but if 6 you actually want to validate the constructed 5 object is what you thought it was going 4 to be, you can use a Capture. It would 3 look something like:
Capture<OtherObj> capturedOtherObj = new Capture<OtherObj>();
mockDao.insert(capture(capturedOtherObj));
replay(mockDao);
objUnderTest.myMethod();
assertThat("captured what you expected", capturedOtherObj.getValue().getId(),
equalTo(expectedId));
Also, PowerMock has the ability 2 to expect an object to be constructed, so 1 you could look into that if you wanted.
Note also that if you use EasyMock.createStrictMock();
, the order of 3 the method calls is also important and if 2 you break this rule, it would throw an unexpected 1 method call.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.