java.lang.IllegalStateException:不兼容的返回值类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5269931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 10:20:33  来源:igfitidea点击:

java.lang.IllegalStateException: incompatible return value type

javaunit-testingjakarta-eeeasymock

提问by Dinesh

I am using EasyMock to create mock classes in test cases.

我正在使用 EasyMock 在测试用例中创建模拟类。

expect(entity.getType()).andReturn("string");

Type belongs to the Stringdatatype. In my development environment it is working fine. But If I transfer to my server and take build, it is failing with following error:

类型属于String数据类型。在我的开发环境中,它运行良好。但是如果我转移到我的服务器并进行构建,它会失败并出现以下错误:

java.lang.IllegalStateException: incompatible return value type

I don't know why it is failing in server and getting executed in my development machine.

我不知道为什么它在服务器上失败并在我的开发机器上执行。

Development EasyMock version: 2.5.2

开发 EasyMock 版本:2.5.2

采纳答案by Bj?rn

I just had the same problem.

我只是遇到了同样的问题。

I had a partial mock in EasyMock, but forgot to call addMockedMethodfor the method I wanted to set the expectation for.

我在 中进行了部分模拟EasyMock,但忘记调用addMockedMethod我想要为其设置期望的方法。

The error message was the same as above, I'd say that was somewhat misleading.

错误消息与上面相同,我认为这有点误导。

回答by Eduard Wirch

In my case the method was finalon which I called expecton. So EasyMockwas not able to mock the method and thus did not record the method invocation.

就我而言,该方法是final我调用的方法expect。所以EasyMock无法模拟方法,因此没有记录方法调用。

回答by palacsint

Make sure that your entityobject is not a simple POJO (eg. new Entity()), and it was created with the createMock()methods of EasyMock.

确保您的entity对象不是简单的 POJO(例如new Entity()),并且它是使用createMock()EasyMock的方法创建的。

回答by rogerdpack

For me, I had to remember to call reset(...) on it after having used it once, or I (bizarrely) got this error message calling expect on it a second time.

对我来说,我必须记得在使用它一次后调用 reset(...) ,或者我(奇怪地)第二次收到这个错误消息调用 expect 。