0
我有一个非平凡的公共接口类型和非平凡我的意思是它返回其他UD公共接口的集合,例如如何解决错误“Mockito不能模拟这个类:接口”?
public interface SomeInterface {
//--------------------------------------------------------------------
String getSomething1(String input1, String input2) throws SomeException;
//--------------------------------------------------------------------
Map<String, String> getSomething2(String input1) throws SomeException;
//--------------------------------------------------------------------
String getSomething3(SomeOtherInterface input3) throws SomeException;
//--------------------------------------------------------------------
Map<String, String> getSomething4(Map<String, SomeOtherInterface> input1,
SomeOtherMoreInterface input2, String input3) throws SomeException;
//--------------------------------------------------------------------
SomeOtherInterface[] getSomething5(String[] input1) throws SomeException;
}
然后我试图创建这个接口的模拟如下:
import org.junit.Assert;
import static org.mockito.Mockito.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
// Mockito produces the RTE below
SomeInterface myMock = mock(SomeInterface.class);
,但这又似乎太多Mockito处理和我得到的不是非常翔实RTE:
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: interface somepackage.SomeInterface.
Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.
Java : 1.8
JVM vendor name : Oracle Corporation
JVM vendor version : 25.11-b03
JVM name : Java HotSpot(TM) 64-Bit Server VM
JVM version : 1.8.0_11-b12
JVM info : mixed mode
OS name : Windows 7
OS version : 6.1
Underlying exception : java.lang.IllegalArgumentException: object is not an instance of declaring class
有没有解决这些错误的方法?有没有Mockito需要能够模拟UD接口的需求列表?
我将几乎可以肯定,使用“共创美好模拟”时EasyMock没那么挑剔特别不...
我通过进口的Maven的Mockito这样的:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.5.0</version>
<scope>test</scope>
</dependency>
请提供完整的例外以及相关的测试代码,以了解您是如何设置它的。我的猜测是,接口“SomeInterface”不是问题,而是接口使用的其他接口/例外之一。 – hotzst