GooglePlayReceiver extends Service implements ExecutionDelegator.JobFinishedCallback { @Override public final int onStartCommand(Intent intent, int flags, int startId) { try { super.onStartCommand(intent, flags, startId); if (intent == null) { Log.w(TAG, ERROR_NULL_INTENT); return START_NOT_STICKY; } String action = intent.getAction(); if (ACTION_EXECUTE.equals(action)) { getExecutionDelegator().executeJob(prepareJob(intent)); return START_NOT_STICKY; } else if (ACTION_INITIALIZE.equals(action)) { return START_NOT_STICKY; } Log.e(TAG, ERROR_UNKNOWN_ACTION); return START_NOT_STICKY; } finally { synchronized (callbacks) { latestStartId = startId; if (callbacks.isEmpty()) { stopSelf(latestStartId); } } } }  @Override final int onStartCommand(Intent intent, int flags, int startId); @Nullable @Override IBinder onBind(Intent intent); @Override void onJobFinished(@NonNull JobInvocation js, @JobResult int result);  }
@Test public void onStartCommand_nullIntent() { assertResultWasStartNotSticky(receiver.onStartCommand(null, 0, 101)); verify(receiver).stopSelf(101); }
@Test public void onStartCommand_initAction() { Intent initIntent = new Intent("com.google.android.gms.gcm.SERVICE_ACTION_INITIALIZE"); assertResultWasStartNotSticky(receiver.onStartCommand(initIntent, 0, 101)); verify(receiver).stopSelf(101); }
@Test public void onStartCommand_unknownAction() { Intent unknownIntent = new Intent("com.example.foo.bar"); assertResultWasStartNotSticky(receiver.onStartCommand(unknownIntent, 0, 101)); assertResultWasStartNotSticky(receiver.onStartCommand(unknownIntent, 0, 102)); assertResultWasStartNotSticky(receiver.onStartCommand(unknownIntent, 0, 103)); InOrder inOrder = inOrder(receiver); inOrder.verify(receiver).stopSelf(101); inOrder.verify(receiver).stopSelf(102); inOrder.verify(receiver).stopSelf(103); }
@Test public void onStartCommand_executeActionWithEmptyExtras() { Intent execIntent = new Intent("com.google.android.gms.gcm.ACTION_TASK_READY"); assertResultWasStartNotSticky(receiver.onStartCommand(execIntent, 0, 101)); verify(receiver).stopSelf(101); }