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?