测试从 AsyncQueryHandler 继承的类
我有以下课程:
public class SomeQueryHandler extends AsyncQueryHandler {
private SoftReference<Handler> handler;
public SomeQueryHandler(Handler handler, ContentResolver cr) {
super(cr);
this.handler = new SoftReference<Handler>(handler);
}
public void load(int token) {
this.startQuery(token, ...);
}
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
super.onQueryComplete(token, cookie, cursor);
try {
if (handler != null && handler.get() != null) {
handler.get().obtainMessage(token, cursor).sendToTarget();
}
} catch (Exception e) {
...;
}
}
}
并且我对该课程进行了junit测试。我创建 Handler,将其传递给实例 SomeQueryHandler
,调用load(...)
并等待来自onQueryComplete
的消息。但我从来没有陷入onQueryComplete
。
问题:如何让 SomeQueryHandler
触发 onQueryComplete
?
I have the following class:
public class SomeQueryHandler extends AsyncQueryHandler {
private SoftReference<Handler> handler;
public SomeQueryHandler(Handler handler, ContentResolver cr) {
super(cr);
this.handler = new SoftReference<Handler>(handler);
}
public void load(int token) {
this.startQuery(token, ...);
}
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
super.onQueryComplete(token, cookie, cursor);
try {
if (handler != null && handler.get() != null) {
handler.get().obtainMessage(token, cursor).sendToTarget();
}
} catch (Exception e) {
...;
}
}
}
And I have junit test for this class. I create Handler, pass it to the instance ofSomeQueryHandler
, call load(...)
and wait for message from onQueryComplete
. But I never fall into onQueryComplete
.
Question: how to make SomeQueryHandler
to fire onQueryComplete
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论