设班福:
public class Foo {
private Unmarshaller unmarshaller;
public Foo(Unmarshaller unmarshaller) {}
}以下测试失败:
@Test
public void test() {
Foo packagingJobSource2 = mock(Foo.class);
}...with错误:
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class com.bell.cts.fonse.vod.streaming.services.adapter.cron.avcm.packagingjob.loading.xmlstorage.Foo.
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 : 9
JVM vendor name : Oracle Corporation
JVM vendor version : 9.0.1+11
JVM name : Java HotSpot(TM) 64-Bit Server VM
JVM version : 9.0.1+11
JVM info : mixed mode
OS name : Mac OS X
OS version : 10.13.2我尝试使用JDK 8而不是9,它运行得很好。我不知道它为什么会失败,也不知道我怎样才能让它成功。
当Unmarshaller是依赖项时,这个问题就会特别发生。如果你把它改为另一种类型,比如String,它会工作.
发布于 2017-12-20 08:30:14
这样做的可能原因是当您在 is not resolved by default.类路径上编译或运行代码时,。
如果您目前依赖的是类路径,而不是(计划)迁移到使用Java平台模块系统(JPMS),则可以使用迁移指南中所述的(1)选项,并且在运行测试时将VM arg添加到执行中,如下所示:
--add-modules java.xml.bindhttps://stackoverflow.com/questions/47894024
复制相似问题