我们如何测试一些课外发送的通知?
例如,在下面的代码中,上下文是一个外部依赖项。在写 Junit 时,我嘲笑它。有没有办法验证执行了哪个“sendNotification”调用?
Class SomeClass{
JsonRpcContext context;
public void someMethod(String arg1,String arg2) throws Exception {
if(someConditionIsMet){
//Do some stuff
context.sendNotification("agentservice", "agentconnected", "Agent session started");
}else{
//Do Some Stuff
context.sendNotification("agentservice", "agentnotconnected", "Error occurred on server side for agent session start");
}
}
}