我有一个这样的类实现Runnable
public Processor implements Runnable{
public void run() {
while (true) {
//some code
sendRequest(object);
}
}
}
public void sendRequest(Object, object){
// do something to send the event
}
}
Run Code Online (Sandbox Code Playgroud)
并在其他预紧课上。我用
Processor processor = new Processor();
ExecutorService executor = Executors.newCachedThreadPool();
executor.execute(processor)
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何对单元调用sendRequest方法进行调用?
我有一个Event
类,它使用构建器模式来设置字段,最后将字段添加到JSON
对象中。
public class Event{
private EventProcessor eventProcessor = new EventProcessor();
private String userName;
private String userID;
public Event setUserName(String userName){
this.userName = userName;
return this;
}
public Event setUserID(String userID){
this.userID = userID;
return this;
}
public void toJson(){
JSONObject json = new JSONObject();
if(null != userName)
json.put("userName", userName);
if(null != userID)
json.put("userID", userID);
// need help to convert json to "event"
eventProcessor.addToQueue(event);
}
}
Run Code Online (Sandbox Code Playgroud)
事件处理器类
public class EventProcessor{
static{
EventQueue eventQueue = new EventQueue<Event>();
} …
Run Code Online (Sandbox Code Playgroud) 我有一个带有publish()方法的A类.在该方法中将调用另一个方法并将类A对象作为参数传递给类B.
public class A {
public void publish() {
ClassB classb = new ClassB();
classb.sendRequest(this)
}
}
Run Code Online (Sandbox Code Playgroud)
问题是如何使用Mockito来验证sendRequest
调用publish()方法时调用方法?我是Mockito的新手.