【发布时间】:2019-01-31 08:52:12
【问题描述】:
我正在尝试测试 Kafka 回调 onFailure 方法:
@Override
public void onFailure(Throwable ex) {
logger.error("Failure while sending message in kafka.", ex);
}
My test case code using Mockito. I am setting exception in object of class SettableListenableFuture.
SettableListenableFuture<SendResult<String, DeserializationResult<EnvelopeExpanded<SpecificRecord>>>> future2 = new SettableListenableFuture<>();
future2.setException(new Exception("Could not publish to Kafka"));
Exception ex = new Exception("Could not publish to Kafka");
verify(logger, times(1)).error("Failure while sending message in kafka.", ex);
我收到了这个错误
Argument(s) are different! Wanted:
logger.error(
"Failure while sending message in kafka.",
java.lang.Exception: Could not publish to Kafka
);
Actual invocation has different arguments:
logger.error(
"Failure while sending message in kafka.",
java.lang.Exception: Could not publish to Kafka
);
想要的和实际的参数都是一样的,但它仍然会抛出错误。谁能帮我解决这个问题??
【问题讨论】:
标签: java spring-boot junit mockito