FirebaseJobDispatcher { @ScheduleResult public int schedule(@NonNull Job job) { if (!driver.isAvailable()) { return SCHEDULE_RESULT_NO_DRIVER_AVAILABLE; } return driver.schedule(job); } FirebaseJobDispatcher(@NonNull Driver driver); @ScheduleResult int schedule(@NonNull Job job); @CancelResult int cancel(@NonNull String tag); @CancelResult int cancelAll(); void mustSchedule(@NonNull Job job); ValidationEnforcer getValidator(); @NonNull Job.Builder newJobBuilder(); RetryStrategy newRetryStrategy(
      @RetryPolicy int policy, int initialBackoff, int maximumBackoff); static final int SCHEDULE_RESULT_SUCCESS; static final int SCHEDULE_RESULT_UNKNOWN_ERROR; static final int SCHEDULE_RESULT_NO_DRIVER_AVAILABLE; static final int SCHEDULE_RESULT_UNSUPPORTED_TRIGGER; static final int SCHEDULE_RESULT_BAD_SERVICE; static final int CANCEL_RESULT_SUCCESS; static final int CANCEL_RESULT_UNKNOWN_ERROR; static final int CANCEL_RESULT_NO_DRIVER_AVAILABLE; }
@Test public void testSchedule_passThrough() throws Exception { final int[] possibleResults = { FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS, FirebaseJobDispatcher.SCHEDULE_RESULT_NO_DRIVER_AVAILABLE, FirebaseJobDispatcher.SCHEDULE_RESULT_BAD_SERVICE, FirebaseJobDispatcher.SCHEDULE_RESULT_UNKNOWN_ERROR, FirebaseJobDispatcher.SCHEDULE_RESULT_UNSUPPORTED_TRIGGER }; for (int result : possibleResults) { when(driver.schedule(null)).thenReturn(result); assertEquals(result, dispatcher.schedule(null)); } verify(driver, times(possibleResults.length)).schedule(null); }
@Test public void testSchedule_unavailable() throws Exception { setDriverAvailability(false); assertEquals( FirebaseJobDispatcher.SCHEDULE_RESULT_NO_DRIVER_AVAILABLE, dispatcher.schedule(null)); verify(driver, never()).schedule(null); }