开发者

Testing of the class inherited from AsyncQueryHandler

开发者 https://www.devze.com 2023-04-04 05:29 出处:网络
I have the following class: public class SomeQueryHandler extends AsyncQueryHandler { private SoftReference<Handler> handler;

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

精彩评论

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