@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(); }
@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 canEatErrorsWhenAsked() throws Exception { Task task = mock(Task.class); Exception e = new Exception(); doThrow(e).when(task).call(); Intent intent = GoroService.taskIntent(application, task) .putExtra(GoroService.EXTRA_IGNORE_ERROR, true); service.onStartCommand(intent, 0, 1); queues.executeAll(); // and nothing happens }
@Test public void serviceContextShouldBeInjected() { Task task = mock(Task.class); service.onStartCommand(GoroService.taskIntent(application, task), 0, 1); verify(task).injectServiceContext(service); }
@Test public void shouldScheduleTasksCreatedWithFactoryMethod() { service.onStartCommand(GoroService.taskIntent(application, task), 0, 1); queues.executeAll(); assertThat(executed).isTrue(); }
@Test public void shouldNotEatErrors() throws Exception { Task task = mock(Task.class); Exception e = new Exception(); doThrow(e).when(task).call(); service.onStartCommand(GoroService.taskIntent(application, task), 0, 1); try { queues.executeAll(); fail("Error was not rethrown"); } catch (GoroException ge) { assertThat(ge.getCause()).isSameAs(e); } }