### Question:
SubmissionTimePolicy implements DeliveryPolicy { @Override public void handleDeliveryAttempt(boolean successful) { if (successful) { lastSubmittedTime = System.currentTimeMillis(); context.getSystem().getPreferences().putLong(SUBMITTED_TIME_KEY, lastSubmittedTime); } } SubmissionTimePolicy(AnalyticsContext context, Long waitInterval); @Override boolean isAllowed(); @Override void handleDeliveryAttempt(boolean successful);  }### Answer:
@Test public void handleDeliveryAttempt_successfulDelivery_submissionTimeUpdated() { SubmissionTimePolicy target = new SubmissionTimePolicy(mockContext, 100l); target.handleDeliveryAttempt(true); ArgumentCaptor<Long> timestamp = ArgumentCaptor.forClass(Long.class); verify(mockPreferences, times(1)).putLong(eq("SubmissionTimePolicy.submissionTime"), timestamp.capture()); long now = System.currentTimeMillis(); assertThat(timestamp.getValue(), is(lessThan(now + 1000))); assertThat(timestamp.getValue(), is(greaterThan(now - 1000))); }
@Test public void handleDeliveryAttempt_failedDelivery_submissionTimeNotUpdated() { SubmissionTimePolicy target = new SubmissionTimePolicy(mockContext, 100l); target.handleDeliveryAttempt(false); verify(mockPreferences, times(0)).putLong(anyString(), anyLong()); }