开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜