GoroService extends Service { @Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent != null) { Callable<?> task = getTaskFromExtras(intent); if (task != null) { injectContext(task); String queueName = intent.hasExtra(EXTRA_QUEUE_NAME) ? intent.getStringExtra(EXTRA_QUEUE_NAME) : Goro.DEFAULT_QUEUE; ObservableFuture<?> future = getBinder().goro.schedule(queueName, task); if (!intent.getBooleanExtra(EXTRA_IGNORE_ERROR, false)) { ensureErrorWillBeThrown(future); } } if (intent.hasExtra(EXTRA_NOTIFICATION_BUNDLE)) { Bundle bundle = intent.getBundleExtra(EXTRA_NOTIFICATION_BUNDLE); if (bundle != null) { Notification notification = bundle.getParcelable(EXTRA_NOTIFICATION); int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, 0); if (notification != null) { startForeground(notificationId, notification); } } } } return START_STICKY; }  static void setup(final Context context, final Goro goro); static Intent foregroundTaskIntent(final Context context,
                                                                                 final String queueName,
                                                                                 final T task,
                                                                                 final int notificationId,
                                                                                 final Notification notification); static Intent foregroundTaskIntent(final Context context,
                                                                                 final T task,
                                                                                 final int notificationId,
                                                                                 final Notification notification); static Intent taskIntent(final Context context,
                                                                       final String queueName,
                                                                       final T task); static Intent taskIntent(final Context context,
                                                                       final T task); static void bind(final Context context, final ServiceConnection connection); static void unbind(final Context context, final ServiceConnection connection); static Callable<?> getTaskFromExtras(final Intent intent); @Override int onStartCommand(final Intent intent, final int flags, final int startId); @Override IBinder onBind(final Intent intent); @Override boolean onUnbind(final Intent intent); @Override void onRebind(final Intent intent); Goro getGoro(); static final String EXTRA_QUEUE_NAME; static final String EXTRA_IGNORE_ERROR; }
@Test public void shouldScheduleTasksPassedInCommandIntent() { Intent command = new Intent(); command.putExtra(GoroService.EXTRA_TASK, task); service.onStartCommand(command, 0, 1); queues.executeAll(); assertThat(executed).isTrue(); }
@Test public void shouldScheduleTasksPassedInCommandIntentWrappedInBundle() { Intent command = new Intent(); Bundle bundle = new Bundle(); bundle.putParcelable(GoroService.EXTRA_TASK, task); command.putExtra(GoroService.EXTRA_TASK_BUNDLE, bundle); service.onStartCommand(command, 0, 1); queues.executeAll(); assertThat(executed).isTrue(); }