
com.xtremelabs.robolectric.util.RobolectricBackgroundExecutorService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of robolectric Show documentation
Show all versions of robolectric Show documentation
An alternative Android testing framework.
package com.xtremelabs.robolectric.util;
import com.xtremelabs.robolectric.Robolectric;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class RobolectricBackgroundExecutorService implements ExecutorService {
@Override public void shutdown() {
throw new UnsupportedOperationException();
}
@Override public List shutdownNow() {
throw new UnsupportedOperationException();
}
@Override public boolean isShutdown() {
throw new UnsupportedOperationException();
}
@Override public boolean isTerminated() {
throw new UnsupportedOperationException();
}
@Override public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException {
throw new UnsupportedOperationException();
}
@Override public Future submit(Callable tCallable) {
return schedule(new FutureTask(tCallable));
}
@Override public Future submit(Runnable runnable, T t) {
return schedule(new FutureTask(runnable, t));
}
@Override public Future> submit(Runnable runnable) {
return submit(runnable, null);
}
private Future schedule(final FutureTask futureTask) {
Robolectric.getShadowApplication().getBackgroundScheduler().post(new Runnable() {
@Override public void run() {
futureTask.run();
}
});
return futureTask;
}
@Override
public List> invokeAll(Collection extends Callable> callables) throws InterruptedException {
throw new UnsupportedOperationException();
}
@Override
public List> invokeAll(Collection extends Callable> callables, long l, TimeUnit timeUnit) throws InterruptedException {
throw new UnsupportedOperationException();
}
@Override
public T invokeAny(Collection extends Callable> callables) throws InterruptedException, ExecutionException {
throw new UnsupportedOperationException();
}
@Override
public T invokeAny(Collection extends Callable> callables, long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
throw new UnsupportedOperationException();
}
@Override public void execute(Runnable runnable) {
submit(runnable);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy