【发布时间】:2016-07-17 03:29:48
【问题描述】:
我正在为 JestClient 包装器编写单元测试。我正在尝试使用 Mockito 模拟 JestClient,但出现以下错误:
Mockito cannot mock this class: interface io.searchbox.client.JestClient
Mockito can only mock visible & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.
这是我定义模拟的方式:
@Bean(name = Identifiers.JEST_CLIENT)
@Profile(Identifiers.PROFILE_UNIT_TEST)
public JestClient getJestClient() {
JestClient client = Mockito.mock(JestClient.class);
return client;
}
我不确定为什么会出现错误,因为 JestClient 只是一个接口。我正在使用:
开玩笑:0.1.6
Mockito:2.0.36-beta
春季:4.2.4
编辑:我认为问题在于 Elasticsearch 库。我使用的是 Elasticsearch 1.5.2;当我切换到 2.2.0 时,问题就消失了。不幸的是,这对我没有帮助,因为我正在与之交谈的集群在 1.5.2 上运行。
【问题讨论】:
-
添加完整的堆栈跟踪。似乎这是一个错误,或者您没有包含足够的库。
-
我认为问题在于 Elasticsearch 1.5.2。当我更新我的库以使用 2.2.0 时,错误消失了。不幸的是,我正在使用的集群使用 1.5.2,并且我之前使用的几个类已被删除。
标签: java unit-testing mockito elasticsearch-jest