ConstraintChecker { public boolean areConstraintsSatisfied(JobInvocation job) { int jobConstraints = Constraint.compact(job.getConstraints()); return areNetworkConstraintsSatisfied(jobConstraints); } ConstraintChecker(Context context); boolean areConstraintsSatisfied(JobInvocation job);  }
@Test public void testAreConstraintsSatisfied_anyNetworkRequired_satisfied() { JobInvocation job = jobBuilder.setConstraints(Constraint.uncompact(Constraint.ON_ANY_NETWORK)).build(); shadowNetworkInfo.setConnectionStatus( true); assertThat(constraintChecker.areConstraintsSatisfied(job)).isTrue(); }
@Test public void testAreConstraintsSatisfied_anyNetworkRequired_unsatisfied_notConnected() { JobInvocation job = jobBuilder.setConstraints(Constraint.uncompact(Constraint.ON_ANY_NETWORK)).build(); shadowNetworkInfo.setConnectionStatus( false); assertThat(constraintChecker.areConstraintsSatisfied(job)).isFalse(); }
@Test public void testAreConstraintsSatisfied_anyNetworkRequired_unsatisfied_nullNetworkInfo() { JobInvocation job = jobBuilder.setConstraints(Constraint.uncompact(Constraint.ON_ANY_NETWORK)).build(); shadowConnectivityManager.setActiveNetworkInfo(null); assertThat(constraintChecker.areConstraintsSatisfied(job)).isFalse(); }
@Test public void testAreConstraintsSatisfied_unmeteredNetworkRequired_satisfied() { JobInvocation job = jobBuilder.setConstraints(Constraint.uncompact(Constraint.ON_UNMETERED_NETWORK)).build(); shadowNetworkInfo.setConnectionStatus( true); setNetworkMetered(false); assertThat(constraintChecker.areConstraintsSatisfied(job)).isTrue(); }
@Test public void testAreConstraintsSatisfied_unmeteredNetworkRequired_unsatisfied_networkDisconnected() { JobInvocation job = jobBuilder.setConstraints(Constraint.uncompact(Constraint.ON_UNMETERED_NETWORK)).build(); shadowNetworkInfo.setConnectionStatus( false); setNetworkMetered(false); assertThat(constraintChecker.areConstraintsSatisfied(job)).isFalse(); }
@Test public void testAreConstraintsSatisfied_unmeteredNetworkRequired_unsatisfied_networkMetered() { JobInvocation job = jobBuilder.setConstraints(Constraint.uncompact(Constraint.ON_UNMETERED_NETWORK)).build(); shadowNetworkInfo.setConnectionStatus( true); setNetworkMetered(true); assertThat(constraintChecker.areConstraintsSatisfied(job)).isFalse(); }
@Test public void testAreConstraintsSatisfied_nonNetworkConstraint() { JobInvocation job = jobBuilder.setConstraints(Constraint.uncompact(Constraint.DEVICE_IDLE)).build(); assertThat(constraintChecker.areConstraintsSatisfied(job)).isTrue(); }
@Test public void testAreConstraintsSatisfied_nonNetworkConstraints() { JobInvocation job = jobBuilder .setConstraints( Constraint.uncompact(Constraint.DEVICE_IDLE | Constraint.DEVICE_CHARGING)) .build(); assertThat(constraintChecker.areConstraintsSatisfied(job)).isTrue(); }
@Test public void testAreConstraintsSatisfied_anyNetworkRequired_satisfied_includesNonNetworkConstraints() { JobInvocation job = jobBuilder .setConstraints( Constraint.uncompact( Constraint.DEVICE_IDLE | Constraint.DEVICE_CHARGING | Constraint.ON_ANY_NETWORK)) .build(); shadowNetworkInfo.setConnectionStatus( true); assertThat(constraintChecker.areConstraintsSatisfied(job)).isTrue(); }