@Test public void testValidate_trigger() throws Exception { Map<JobTrigger, String> testCases = new HashMap<>(); testCases.put(Trigger.NOW, null); testCases.put(Trigger.executionWindow(0, 100), null); ContentUriTrigger contentUriTrigger = Trigger.contentUriTrigger( Arrays.asList( new ObservedUri( ContactsContract.AUTHORITY_URI, Flags.FLAG_NOTIFY_FOR_DESCENDANTS))); testCases.put(contentUriTrigger, null); for (Entry<JobTrigger, String> testCase : testCases.entrySet()) { List<String> validationErrors = validator.validate(testCase.getKey()); if (testCase.getValue() == null) { assertNull("Expected no validation errors for trigger", validationErrors); } else { assertTrue( "Expected validation errors to contain \"" + testCase.getValue() + "\"", validationErrors.contains(testCase.getValue())); } } }
@Nullable @Override @CallSuper public List<String> validate(@NonNull JobParameters job) { List<String> errors; errors = mergeErrorLists(null, validate(job.getTrigger())); errors = mergeErrorLists(errors, validate(job.getRetryStrategy())); if (job.isRecurring() && job.getTrigger() == Trigger.NOW) { errors = addError(errors, "ImmediateTriggers can't be used with recurring jobs"); } errors = mergeErrorLists(errors, validateForTransport(job.getExtras())); if (job.getLifetime() > Lifetime.UNTIL_NEXT_BOOT) { errors = mergeErrorLists(errors, validateForPersistence(job.getExtras())); } errors = mergeErrorLists(errors, validateTag(job.getTag())); errors = mergeErrorLists(errors, validateService(job.getService())); return errors; }
DefaultJobValidator implements JobValidator { @Nullable @Override @CallSuper public List<String> validate(@NonNull JobParameters job) { List<String> errors; errors = mergeErrorLists(null, validate(job.getTrigger())); errors = mergeErrorLists(errors, validate(job.getRetryStrategy())); if (job.isRecurring() && job.getTrigger() == Trigger.NOW) { errors = addError(errors, "ImmediateTriggers can't be used with recurring jobs"); } errors = mergeErrorLists(errors, validateForTransport(job.getExtras())); if (job.getLifetime() > Lifetime.UNTIL_NEXT_BOOT) { errors = mergeErrorLists(errors, validateForPersistence(job.getExtras())); } errors = mergeErrorLists(errors, validateTag(job.getTag())); errors = mergeErrorLists(errors, validateService(job.getService())); return errors; } }
DefaultJobValidator implements JobValidator { @Nullable @Override @CallSuper public List<String> validate(@NonNull JobParameters job) { List<String> errors; errors = mergeErrorLists(null, validate(job.getTrigger())); errors = mergeErrorLists(errors, validate(job.getRetryStrategy())); if (job.isRecurring() && job.getTrigger() == Trigger.NOW) { errors = addError(errors, "ImmediateTriggers can't be used with recurring jobs"); } errors = mergeErrorLists(errors, validateForTransport(job.getExtras())); if (job.getLifetime() > Lifetime.UNTIL_NEXT_BOOT) { errors = mergeErrorLists(errors, validateForPersistence(job.getExtras())); } errors = mergeErrorLists(errors, validateTag(job.getTag())); errors = mergeErrorLists(errors, validateService(job.getService())); return errors; } DefaultJobValidator(@NonNull Context context); }
DefaultJobValidator implements JobValidator { @Nullable @Override @CallSuper public List<String> validate(@NonNull JobParameters job) { List<String> errors; errors = mergeErrorLists(null, validate(job.getTrigger())); errors = mergeErrorLists(errors, validate(job.getRetryStrategy())); if (job.isRecurring() && job.getTrigger() == Trigger.NOW) { errors = addError(errors, "ImmediateTriggers can't be used with recurring jobs"); } errors = mergeErrorLists(errors, validateForTransport(job.getExtras())); if (job.getLifetime() > Lifetime.UNTIL_NEXT_BOOT) { errors = mergeErrorLists(errors, validateForPersistence(job.getExtras())); } errors = mergeErrorLists(errors, validateTag(job.getTag())); errors = mergeErrorLists(errors, validateService(job.getService())); return errors; } DefaultJobValidator(@NonNull Context context); @Nullable @Override @CallSuper List<String> validate(@NonNull JobParameters job); @Nullable @Override @CallSuper List<String> validate(@NonNull JobTrigger trigger); @Nullable @Override @CallSuper List<String> validate(@NonNull RetryStrategy retryStrategy); }
DefaultJobValidator implements JobValidator { @Nullable @Override @CallSuper public List<String> validate(@NonNull JobParameters job) { List<String> errors; errors = mergeErrorLists(null, validate(job.getTrigger())); errors = mergeErrorLists(errors, validate(job.getRetryStrategy())); if (job.isRecurring() && job.getTrigger() == Trigger.NOW) { errors = addError(errors, "ImmediateTriggers can't be used with recurring jobs"); } errors = mergeErrorLists(errors, validateForTransport(job.getExtras())); if (job.getLifetime() > Lifetime.UNTIL_NEXT_BOOT) { errors = mergeErrorLists(errors, validateForPersistence(job.getExtras())); } errors = mergeErrorLists(errors, validateTag(job.getTag())); errors = mergeErrorLists(errors, validateService(job.getService())); return errors; } DefaultJobValidator(@NonNull Context context); @Nullable @Override @CallSuper List<String> validate(@NonNull JobParameters job); @Nullable @Override @CallSuper List<String> validate(@NonNull JobTrigger trigger); @Nullable @Override @CallSuper List<String> validate(@NonNull RetryStrategy retryStrategy); static final int MAX_TAG_LENGTH; static final int MAX_EXTRAS_SIZE_BYTES; }