我有一个简单的界面,但是当我尝试模拟它时,我的测试失败了。这是错误。
Mockito cannot mock this class: interface pmb.net.conn.types.INetworkLayer.
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.0-b70
JVM name : Java HotSpot(TM) 64-Bit Server VM
JVM version : 1.8.0-b132
JVM info : mixed mode
OS name : Windows 8.1
OS version : 6.3
Underlying exception : java.lang.IllegalArgumentException: object is not an
instance of declaring class
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: interface pmb.net.conn.types.INetworkLayer.
这是界面。
interface INetworkLayer {
fun getDbStateHash(peerInfo: IPeerInfo): String
fun getBlockMap(peerInfo: IPeerInfo, blockNumber: Int): IBlockMap
fun getBlockPackages(blockNumber: Int,
packageIdsList: Iterable<String>): Iterable<BlockChunk>
}
这是我测试代码的一部分
describe("Description") {
val peerInfoMock = mock(IPeerInfo::class)
val networkLayerMock = mock(INetworkLayer::class)
val peer = Peer(peerInfoMock, networkLayerMock)