Skip to content

Instantly share code, notes, and snippets.

@CDRussell
Last active June 2, 2016 08:32
Show Gist options
  • Save CDRussell/4150ac29676b2a2110daf24f295ba5e0 to your computer and use it in GitHub Desktop.
Save CDRussell/4150ac29676b2a2110daf24f295ba5e0 to your computer and use it in GitHub Desktop.
Helper functions for working with Tasks from BoltsAndroid
import java.util.concurrent.Executor;
import bolts.Task;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public abstract class TaskHelper {
public static void assertTaskFinishedSuccessfully(Task<?> task) {
assertTrue(task.isCompleted());
assertFalse(task.isCancelled());
assertFalse(task.isFaulted());
}
public static void assertTaskFailed(Task<?> task) {
assertTrue(task.isCompleted());
assertFalse(task.isCancelled());
assertTrue(task.isFaulted());
}
public static Executor executeImmediately() {
return Runnable::run;
}
}
@CDRussell
Copy link
Author

If you can't use Retrolambda, then you can replace Runnable::run with

new Executor() {
    @Override
    public void execute(Runnable command) {
        command.run();
    }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment