简体   繁体   English

Easymock不兼容的返回值类型错误

[英]Easymock incompatible return value type error

I'm trying to create a EasyMock for this particular piece of code, such that innerfValue is of type IJavaValue, which is a subclass of IJavaObject. 我正在尝试为这段特殊代码创建一个EasyMock,这样innerfValue的类型为IJavaValue,它是IJavaObject的子类。 I've tried conventional methods of dealing with this by mocking innerfValue and then just assuming aJavaValue points to innerfValue and mocking the sendmessage method as if it were a method of innerfValue, but its hasen't been working and by the time I get to the end it gives me a incompatible return value type when I do (symbolvalue in this case is a mock object that I made to return after the sendmessage method was called on my mock innerfValue object, not the saem as the symbolValue in the other piece of code): 我试过通过模拟innerfValue然后只是假设aJavaValue指向innerfValue并模拟sendmessage方法就好像它是一个innerfValue的方法一样来处理这个问题的常规方法,但是它还没有工作,当我到达当我这样做时,它给了我一个不兼容的返回值类型(在这种情况下,symbolvalue是我在模拟innerfValue对象上调用sendmessage方法后返回的模拟对象,而不是另一段代码中的symbolValue。 ):

EasyMock.expect(((IJavaObject)symbolValue).toString()).andReturn("aValue");

Here is the piece of code 这是一段代码

IJavaObject aJavaValue = (IJavaObject)innerfValue.getValue();
IJavaObject symbolValue = (IJavaObject) ((IJavaObject)aJavaValue).sendMessage(
    "toString", "()Ljava/lang/String;", null, thread, false);
value = symbolValue.toString();

EasyMock cannot mock the toString() method. EasyMock无法模拟toString()方法。 This is why I was having the issue. 这就是我遇到这个问题的原因。

I see where my problem is. 我知道我的问题在哪里。

If you are using EasyMock.createMockBuilder(XXX.class) 如果您使用的是EasyMock.createMockBuilder(XXX.class)

Make sure you remember to addMockedMethod("methodName").createMock(); 确保你记得addMockedMethod(“methodName”)。createMock();

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

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