我有以下代码......
val list : List[MyClass] = List(new MyClass)
// Doesn't work
doReturn(list).when(localLib).getThing(anyString(), anyString(), anyInt())
// Doesn't work
doReturn(list.asInstanceOf[List[MyClass]]).when(localLib).getExposedDataByDataFileId(anyString(), anyString(), anyInt())
当我进行测试时,我看到......
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
$colon$colon cannot be returned by getThing()
getThing() should return List
***
If you're unsure why you're getting above error read on.
Due to the nature of the syntax above problem might occur because:
1. This exception *might* occur in wrongly written multi-threaded tests.
Please refer to Mockito FAQ on limitations of concurrency testing.
2. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies -
- with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
请注意$colon$colon
这是scala限制
MyClass是一个Java类,但测试是在Scala中