Testing of the class inherited from AsyncQueryHandler
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 of
SomeQueryHandler开发者_高级运维
, call load(...)
and wait for message from onQueryComplete
. But I never fall into onQueryComplete
.
Question: how to make SomeQueryHandler
to fire onQueryComplete
?
精彩评论