我想返回 java.util.List
val cacheManager = mock(classOf[CacheManager])
val cache = mock(classOf[Cache])
when(cacheManager.getCache(anyString)).thenReturn(cache)
when(cache.getKeys.asInstanceOf[List[String]]).thenReturn(List("some_key"))
它编译,但抛出:
java.lang.NullPointerException
at net.sf.ehcache.Cache.checkStatus(Cache.java:2722)
at net.sf.ehcache.Cache.getKeys(Cache.java:1912)
at (last line of code)
我该如何解决?我尝试了几种方法,但没有成功。
方法签名:
public final java.util.List getKeys() throws java.lang.IllegalStateException, net.sf.ehcache.CacheException { /* compiled code */ }