提问人:Tahir Sultan 提问时间:11/18/2023 更新时间:11/18/2023 访问量:26
如何使用 Mockito 测试包含的 lamda 表达式私有方法?
How to test lamda expression included private method using Mockito?
问:
我想测试这段代码。
public void send(String topic, Object value) {
Optional.ofNullable(observer.get(topic)).ifPresent(handler::removeCallbacks);
observer.put(topic, () -> send(topic, value));
MessageObservable observable = MessageSendingObserver.create((isSuccess, publicationReport){
if (shouldBeResend(isSuccess, publicationReport)) {
handler.postDelayed(observer.get(topic), INTERVAL);
}
});
message.publish(topic, value, observable);
}
private boolean shouldBeResend(boolean isSuccess, PublicationReport publicationReport) {
return !isSuccess && publicationReport.getErrorCode() >= 400 && publicationReport.getErrorCode() <= 599;
}
I want to test this code.
我有问题如何嘲笑观察者并强制它在成功时抛出错误或返回值。我正在使用 mockito/junit。有人可以指出我如何实现它吗?也许我的代码是不可测试的?
答: 暂无答案
评论