简体   繁体   English

java.lang.IllegalStateException:前面的方法调用getLast(...)的行为定义缺失

[英]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: 我已经修改了一个现有的类,当我尝试使用ant构建它时,出现以下单元测试失败错误:

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) java.lang.IllegalStateException:在org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:43)处的前述方法调用getLast(class mypackage.model.MyObj,1)的行为定义缺失.invoke(ObjectMethodsFilter.java:73)在org.easymock.internal.ClassProxyFactory $ MockMethodInterceptor.intercept(ClassProxyFactory.java:92)在mypackage.service.MyService $$ EnhancerByCGLIB $$ 347f5838.getLast()在mypackage.controller.MyController .myControllerMethod(MyController.java:265)位于mypackage.controller.MyController.myControllerMethodTest(MyControllerTest.java:207)

In MyController.java I've added a piece of code like (the error is at line 265): MyController.java我添加了一段代码(错误在第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: MyControllerTest.java只需调用myControllerMethod ,例如:

207. myController.myControllerMethod(1);

I've already tried to add an "expectation" before the line 207, like: 我已经尝试在第207行之前添加“期望”,例如:

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. 好的,我在示例中发现了EasyMock.replay(myServiceMock)

That's a kind of "activation" of the expectation inserted before. 这是对之前插入的期望的一种“激活”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalStateException:缺少前面方法调用 getMessage(“title”) 的行为定义 - java.lang.IllegalStateException: missing behavior definition for the preceding method call getMessage(“title”) java.lang.IllegalStateException:没有对静态方法可用的模拟的最后一次调用 - java.lang.IllegalStateException: no last call on a mock available for static method IllegalStateException:在同一方法中有两次调用时缺少行为定义 - IllegalStateException: missing behavior definition when having a double call in same method 呼叫记录失败,并出现java.lang.IllegalStateException - Call Recording failed with java.lang.IllegalStateException java.lang.IllegalStateException:找不到方法 - java.lang.IllegalStateException: Could not find method java.lang.IllegalStateException:找不到方法? - java.lang.IllegalStateException: Could not find a method? 方法中带有@Async的java.lang.IllegalStateException - java.lang.IllegalStateException with @Async in method java.lang.IllegalStateException - java.lang.IllegalStateException java.lang.IllegalStateException:没有在bean定义上指定bean类 - java.lang.IllegalStateException: No bean class specified on bean definition java.lang.IllegalStateException:在堆栈上找不到调用#0。 记录方法调用无效? - java.lang.IllegalStateException: can not found call #0 on stack. Invalid call of record method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM