![](/img/trans.png)
[英]I'm need to know how put an interface of a method inside When() mockito method
[英]Mockito - Interface method is called when I need it to call the implementation class
我有一个界面
public abstract interface SomeSetRemote
extends Remote
{
public abstract someMethod getMedata(int paramInt)
throws RemoteException;
}
实现类
public class SomeSet
extends Remote
{
public someMethod getMedata(int paramInt)
throws RemoteException
{
System.Out.println(" Hi I am a class..........);
}
}
问题是我正在测试的方法中有一个调用返回了接口,然后有一个方法调用不起作用,因为它正在接口上进行尝试。
所以,方法调用是这样的
someObject.getSomeSet().getMedata()
someObject.getSomeSet()
返回接口,因此不调用实现类getMedata
。
我如何使Mockito调用实现类方法?
这是旧版代码,因此无法对其进行更改。
谢谢
如您所知,问题出在someObject.getSomeSet()
返回接口。 然后尝试模拟一下:
Remote remoteObj = new SomeSet();
when(someObject.getSomeSet()).thenReturn(remoteObj);
从这里,您可以使用remoteObj
进行remoteObj
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.