
org.robolectric.shadows.ShadowAsyncTaskLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of framework Show documentation
Show all versions of framework Show documentation
An alternative Android testing framework.
The newest version!
package org.robolectric.shadows;
import android.content.Context;
import android.content.AsyncTaskLoader;
import org.robolectric.util.SimpleFuture;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.annotation.Implementation;
import java.util.concurrent.Callable;
@Implements(AsyncTaskLoader.class)
public class ShadowAsyncTaskLoader {
@RealObject private AsyncTaskLoader realObject;
private SimpleFuture future;
public void __constructor__(Context context) {
BackgroundWorker worker = new BackgroundWorker();
future = new SimpleFuture(worker) {
@Override
protected void done() {
try {
final D result = get();
ShadowApplication.getInstance().getForegroundThreadScheduler().post(new Runnable() {
@Override
public void run() {
realObject.deliverResult(result);
}
});
} catch (InterruptedException e) {
// Ignore
}
}
};
}
@Implementation
public void onForceLoad() {
ShadowApplication.getInstance().getBackgroundThreadScheduler().post(new Runnable() {
@Override
public void run() {
future.run();
}
});
}
private final class BackgroundWorker implements Callable {
@Override
public D call() throws Exception {
return realObject.loadInBackground();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy