我有一个非平凡的公共接口类型,并且非平凡我的意思是它返回其他UD公共接口的集合,例如。
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);
然后我尝试按如下方式创建此接口的模拟:
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来说似乎太过分了,我得到的信息并不是很有用:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.5.0</version>
<scope>test</scope>
</dependency>
有没有办法解决这些错误?是否存在Mockito需要能够模拟UD接口的要求列表?
我几乎可以确定EasyMock并非如此挑剔特别是在使用&#34;创建漂亮的模拟&#34; ...
我通过Maven导入Mockito:
{{1}}
答案 0 :(得分:-3)
好的,如果我替换它:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.5.0</version>
<scope>test</scope>
</dependency>
用这个:
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.4</version>
<scope>test</scope>
</dependency>
和此:
import static org.mockito.Mockito.*;
SomeInterface myMock = mock(SomeInterface.class);
用这个:
import static org.easymock.EasyMock.*;
SomeInterface myMock = createMock(SomeInterface.class);
然后我的OP工作完美,而不必要求我的组织的Ops在整个组织范围内更改/升级JVM版本只是因为Mockito ......