SimpleTrial { public boolean isTrialPeriodFinished() { return new Date().getTime() >= trialStartTimestamp + trialDurationInMilliseconds; } SimpleTrial(Context context, Config config); boolean isTrialPeriodFinished(); Date getTrialStartDate(); void updateTrialStartDate(Date trialStartDate);  }
@Test public void oldTimestampMustCauseTrialToBeOver() { Context context = mock(Context.class); TrialFactor factor = mock(TrialFactor.class); when(factor.readTimestamp(any(Context.class))).thenReturn(123L); SimpleTrial trial = new SimpleTrial(context, new SimpleTrial.Config().factors(factor)); verify(factor).persistTimestamp(123L, context); assertTrue(trial.isTrialPeriodFinished()); }
@Test public void noTimestampMustDefaultToCurrentTimestamp() { Context context = mock(Context.class); TrialFactor factor = mock(TrialFactor.class); when(factor.readTimestamp(any(Context.class))) .thenReturn(TrialFactor.NOT_AVAILABLE_TIMESTAMP); long minTimestamp = new Date().getTime(); SimpleTrial trial = new SimpleTrial(context, new SimpleTrial.Config().factors(factor)); long maxTimestamp = new Date().getTime(); verify(factor).persistTimestamp(longThat(between(minTimestamp, maxTimestamp)), eq(context)); assertFalse(trial.isTrialPeriodFinished()); }