简体   繁体   中英

java.lang.IllegalStateException: missing behavior definition for the preceding method call getLast(…)

I've already read similar questions on SO like this , but I can't solve my problem. I've modified an existing class and when I try to build it with ant I get the following unit test failed error:

java.lang.IllegalStateException: missing behavior definition for the preceding method call getLast(class mypackage.model.MyObj, 1) at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:43) at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:73) at org.easymock.internal.ClassProxyFactory$MockMethodInterceptor.intercept(ClassProxyFactory.java:92) at mypackage.service.MyService$$EnhancerByCGLIB$$347f5838.getLast() at mypackage.controller.MyController.myControllerMethod(MyController.java:265) at mypackage.controller.MyController.myControllerMethodTest(MyControllerTest.java:207)

In MyController.java I've added a piece of code like (the error is at line 265):

263. public void myControllerMethod(Integer id) {
264.   String myString = null;
265.   MyObj myObj = (MyObj) myService.getLast(MyObj.class, id);
266.   try {
267.     myString = myObj.getMyProp().getMyObj();
268.   } catch (Exception e) {
269.     myString = "";
270.   }

MyControllerTest.java simply calls myControllerMethod , like:

207. myController.myControllerMethod(1);

I've already tried to add an "expectation" before the line 207, like:

206. EasyMock.expect(myServiceMock.getLast(MyObj.class, 1));

rather than:

206. EasyMock.expect(myServiceMock.getLast(MyObj.class, 1)).andReturn(new MyObj());

But to no avail. Can anyone help me, please?

Ok, I solved with EasyMock.replay(myServiceMock) as I found in this example.

That's a kind of "activation" of the expectation inserted before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM