@Test public void testCheckForIllegalExperimentStartTime() { Experiment mockCurrentExperiment = mock(Experiment.class); Experiment mockUpdateExperiment = mock(Experiment.class); Date updateEndDate = mock(Date.class); Date currentEndDate = mock(Date.class); Date updateStartDate = mock(Date.class); when(mockUpdateExperiment.getStartTime()).thenReturn(updateStartDate); when(updateStartDate.before(any(Date.class))).thenReturn(true); assertIllegalExperimentStartTime(mockCurrentExperiment, mockUpdateExperiment); when(updateStartDate.before(any(Date.class))).thenReturn(false); Date currentStartDate = mock(Date.class); when(mockCurrentExperiment.getStartTime()).thenReturn(currentStartDate); when(currentStartDate.before(any(Date.class))).thenReturn(true); assertIllegalExperimentStartTime(mockCurrentExperiment, mockUpdateExperiment); when(currentStartDate.before(any(Date.class))).thenReturn(false); when(mockUpdateExperiment.getEndTime()).thenReturn(null); when(mockCurrentExperiment.getEndTime()).thenReturn(currentEndDate); when(updateStartDate.after(currentEndDate)).thenReturn(true); assertIllegalExperimentStartTime(mockCurrentExperiment, mockUpdateExperiment); when(currentStartDate.before(any(Date.class))).thenReturn(false); when(mockUpdateExperiment.getEndTime()).thenReturn(updateEndDate); when(updateStartDate.after(updateEndDate)).thenReturn(true); assertIllegalExperimentStartTime(mockCurrentExperiment, mockUpdateExperiment); }
void checkForIllegalExperimentStartTime(Experiment current, Experiment update) { if (update.getStartTime().before(currentDate)) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot set the experiment start time to a value in the past"); } else if (current.getStartTime().before(currentDate)) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime that has already passed"); } else { if (update.getEndTime() != null) { if (update.getStartTime().after(update.getEndTime())) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime to a value beyond the experiment endTime"); } } else { if (update.getStartTime().after(current.getEndTime())) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime to a value beyond the experiment endTime"); } } } }
ExperimentsImpl implements Experiments { void checkForIllegalExperimentStartTime(Experiment current, Experiment update) { if (update.getStartTime().before(currentDate)) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot set the experiment start time to a value in the past"); } else if (current.getStartTime().before(currentDate)) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime that has already passed"); } else { if (update.getEndTime() != null) { if (update.getStartTime().after(update.getEndTime())) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime to a value beyond the experiment endTime"); } } else { if (update.getStartTime().after(current.getEndTime())) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime to a value beyond the experiment endTime"); } } } } }
ExperimentsImpl implements Experiments { void checkForIllegalExperimentStartTime(Experiment current, Experiment update) { if (update.getStartTime().before(currentDate)) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot set the experiment start time to a value in the past"); } else if (current.getStartTime().before(currentDate)) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime that has already passed"); } else { if (update.getEndTime() != null) { if (update.getStartTime().after(update.getEndTime())) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime to a value beyond the experiment endTime"); } } else { if (update.getStartTime().after(current.getEndTime())) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime to a value beyond the experiment endTime"); } } } } @Inject  ExperimentsImpl(@DatabaseRepository ExperimentRepository databaseRepository,
                           @CassandraRepository ExperimentRepository cassandraRepository, Experiments experiments,
                           Buckets buckets, Pages pages, Priorities priorities, ExperimentValidator validator,
                           RuleCache ruleCache, EventLog eventLog); }
ExperimentsImpl implements Experiments { void checkForIllegalExperimentStartTime(Experiment current, Experiment update) { if (update.getStartTime().before(currentDate)) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot set the experiment start time to a value in the past"); } else if (current.getStartTime().before(currentDate)) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime that has already passed"); } else { if (update.getEndTime() != null) { if (update.getStartTime().after(update.getEndTime())) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime to a value beyond the experiment endTime"); } } else { if (update.getStartTime().after(current.getEndTime())) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime to a value beyond the experiment endTime"); } } } } @Inject  ExperimentsImpl(@DatabaseRepository ExperimentRepository databaseRepository,
                           @CassandraRepository ExperimentRepository cassandraRepository, Experiments experiments,
                           Buckets buckets, Pages pages, Priorities priorities, ExperimentValidator validator,
                           RuleCache ruleCache, EventLog eventLog); @Override ExperimentList getExperiments(); @Override List<Application.Name> getApplications(); @Override Map<Application.Name, Set<String>> getTagsForApplications(Collection<Application.Name> applicationNames); @Override Experiment getExperiment(Experiment.ID id); @Override Experiment getExperiment(Application.Name appName, Experiment.Label label); @Override List<Experiment> getExperiments(Application.Name appName); @Override void createExperiment(NewExperiment newExperiment, UserInfo user); @Override void checkStateTransition(Experiment.ID experimentID, Experiment.State currentState,
                                     Experiment.State desiredState); @Override void checkForIllegalUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalPausedRunningUpdate(Experiment experiment, Experiment updates); @Override boolean buildUpdatedExperiment(Experiment experiment, Experiment updates, Experiment.Builder builder,
                                          List<ExperimentAuditInfo> changeList); @Override void updateSegmentationRule(Experiment experiment, UserInfo user); @Override Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user); @Override void updateExperimentState(final Experiment experiment, final Experiment.State state); }
ExperimentsImpl implements Experiments { void checkForIllegalExperimentStartTime(Experiment current, Experiment update) { if (update.getStartTime().before(currentDate)) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot set the experiment start time to a value in the past"); } else if (current.getStartTime().before(currentDate)) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime that has already passed"); } else { if (update.getEndTime() != null) { if (update.getStartTime().after(update.getEndTime())) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime to a value beyond the experiment endTime"); } } else { if (update.getStartTime().after(current.getEndTime())) { throw new IllegalArgumentException("Invalid startTime \"" + update.getStartTime() + "\". " + "Cannot update the experiment startTime to a value beyond the experiment endTime"); } } } } @Inject  ExperimentsImpl(@DatabaseRepository ExperimentRepository databaseRepository,
                           @CassandraRepository ExperimentRepository cassandraRepository, Experiments experiments,
                           Buckets buckets, Pages pages, Priorities priorities, ExperimentValidator validator,
                           RuleCache ruleCache, EventLog eventLog); @Override ExperimentList getExperiments(); @Override List<Application.Name> getApplications(); @Override Map<Application.Name, Set<String>> getTagsForApplications(Collection<Application.Name> applicationNames); @Override Experiment getExperiment(Experiment.ID id); @Override Experiment getExperiment(Application.Name appName, Experiment.Label label); @Override List<Experiment> getExperiments(Application.Name appName); @Override void createExperiment(NewExperiment newExperiment, UserInfo user); @Override void checkStateTransition(Experiment.ID experimentID, Experiment.State currentState,
                                     Experiment.State desiredState); @Override void checkForIllegalUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalTerminatedUpdate(Experiment experiment, Experiment updates); @Override void checkForIllegalPausedRunningUpdate(Experiment experiment, Experiment updates); @Override boolean buildUpdatedExperiment(Experiment experiment, Experiment updates, Experiment.Builder builder,
                                          List<ExperimentAuditInfo> changeList); @Override void updateSegmentationRule(Experiment experiment, UserInfo user); @Override Experiment updateExperiment(final Experiment.ID experimentID, final Experiment updates, final UserInfo user); @Override void updateExperimentState(final Experiment experiment, final Experiment.State state);  }