@Test public void testDelayMet_withMetConstraint() throws InterruptedException { when(mBatteryChargingTracker.getInitialState()).thenReturn(true); OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(TestWorker.class) .setPeriodStartTime(System.currentTimeMillis(), TimeUnit.MILLISECONDS) .setConstraints(new Constraints.Builder() .setRequiresCharging(true) .build()) .build(); insertWork(work); Intent delayMet = CommandHandler.createDelayMetIntent(mContext, work.getStringId()); mSpyDispatcher.postOnMainThread( new SystemAlarmDispatcher.AddRunnable(mSpyDispatcher, delayMet, START_ID)); mLatch.await(TEST_TIMEOUT, TimeUnit.SECONDS); List<String> intentActions = intentActionsFor(mSpyDispatcher.getCommands()); WorkSpecDao workSpecDao = mDatabase.workSpecDao(); WorkSpec workSpec = workSpecDao.getWorkSpec(work.getStringId()); assertThat(mLatch.getCount(), is(0L)); assertThat(intentActions, IsIterableContainingInOrder.contains( CommandHandler.ACTION_DELAY_MET, CommandHandler.ACTION_EXECUTION_COMPLETED, CommandHandler.ACTION_CONSTRAINTS_CHANGED)); assertThat(workSpec.state, is(State.SUCCEEDED)); }
void postOnMainThread(@NonNull Runnable runnable) { mMainHandler.post(runnable); }
SystemAlarmDispatcher implements ExecutionListener { void postOnMainThread(@NonNull Runnable runnable) { mMainHandler.post(runnable); } }
SystemAlarmDispatcher implements ExecutionListener { void postOnMainThread(@NonNull Runnable runnable) { mMainHandler.post(runnable); } SystemAlarmDispatcher(@NonNull Context context); @VisibleForTesting  SystemAlarmDispatcher(
            @NonNull Context context,
            @Nullable Processor processor,
            @Nullable WorkManagerImpl workManager); }
SystemAlarmDispatcher implements ExecutionListener { void postOnMainThread(@NonNull Runnable runnable) { mMainHandler.post(runnable); } SystemAlarmDispatcher(@NonNull Context context); @VisibleForTesting  SystemAlarmDispatcher(
            @NonNull Context context,
            @Nullable Processor processor,
            @Nullable WorkManagerImpl workManager); @Override void onExecuted(
            @NonNull String workSpecId,
            boolean isSuccessful,
            boolean needsReschedule); @MainThread boolean add(@NonNull final Intent intent, final int startId); }
SystemAlarmDispatcher implements ExecutionListener { void postOnMainThread(@NonNull Runnable runnable) { mMainHandler.post(runnable); } SystemAlarmDispatcher(@NonNull Context context); @VisibleForTesting  SystemAlarmDispatcher(
            @NonNull Context context,
            @Nullable Processor processor,
            @Nullable WorkManagerImpl workManager); @Override void onExecuted(
            @NonNull String workSpecId,
            boolean isSuccessful,
            boolean needsReschedule); @MainThread boolean add(@NonNull final Intent intent, final int startId);  }