@Test public void shouldUpdateReturnsTrueWhenLastExecuteWasTodayButBeforeUpdateHour() { var lastExecuteHour = EXECUTION_HOUR - 1; var lastExecuteTime = LocalDate.now(clock).atTime(lastExecuteHour, 0); var actualShouldUpdate = fixedHourJob.shouldExecute(lastExecuteTime); assertThat(actualShouldUpdate).isTrue(); }
@Override public final boolean shouldExecute(LocalDateTime lastExecuteTime) { var now = LocalDateTime.now(clock); var today = LocalDate.now(clock); var yesterday = today.minus(1, ChronoUnit.DAYS); var lastExecuteDate = lastExecuteTime.toLocalDate(); if(yesterday.isAfter(lastExecuteDate)) { return true; } else if(today.isAfter(lastExecuteDate)) { return now.getHour() >= this.jobExecutionHour; } else { return lastExecuteTime.getHour() < this.jobExecutionHour; } }
FixedHourScheduledJob implements ScheduledJob { @Override public final boolean shouldExecute(LocalDateTime lastExecuteTime) { var now = LocalDateTime.now(clock); var today = LocalDate.now(clock); var yesterday = today.minus(1, ChronoUnit.DAYS); var lastExecuteDate = lastExecuteTime.toLocalDate(); if(yesterday.isAfter(lastExecuteDate)) { return true; } else if(today.isAfter(lastExecuteDate)) { return now.getHour() >= this.jobExecutionHour; } else { return lastExecuteTime.getHour() < this.jobExecutionHour; } } }
FixedHourScheduledJob implements ScheduledJob { @Override public final boolean shouldExecute(LocalDateTime lastExecuteTime) { var now = LocalDateTime.now(clock); var today = LocalDate.now(clock); var yesterday = today.minus(1, ChronoUnit.DAYS); var lastExecuteDate = lastExecuteTime.toLocalDate(); if(yesterday.isAfter(lastExecuteDate)) { return true; } else if(today.isAfter(lastExecuteDate)) { return now.getHour() >= this.jobExecutionHour; } else { return lastExecuteTime.getHour() < this.jobExecutionHour; } } protected  FixedHourScheduledJob(Clock clock, int jobExecutionHour); }
FixedHourScheduledJob implements ScheduledJob { @Override public final boolean shouldExecute(LocalDateTime lastExecuteTime) { var now = LocalDateTime.now(clock); var today = LocalDate.now(clock); var yesterday = today.minus(1, ChronoUnit.DAYS); var lastExecuteDate = lastExecuteTime.toLocalDate(); if(yesterday.isAfter(lastExecuteDate)) { return true; } else if(today.isAfter(lastExecuteDate)) { return now.getHour() >= this.jobExecutionHour; } else { return lastExecuteTime.getHour() < this.jobExecutionHour; } } protected  FixedHourScheduledJob(Clock clock, int jobExecutionHour); @Override final boolean shouldExecute(LocalDateTime lastExecuteTime); }
FixedHourScheduledJob implements ScheduledJob { @Override public final boolean shouldExecute(LocalDateTime lastExecuteTime) { var now = LocalDateTime.now(clock); var today = LocalDate.now(clock); var yesterday = today.minus(1, ChronoUnit.DAYS); var lastExecuteDate = lastExecuteTime.toLocalDate(); if(yesterday.isAfter(lastExecuteDate)) { return true; } else if(today.isAfter(lastExecuteDate)) { return now.getHour() >= this.jobExecutionHour; } else { return lastExecuteTime.getHour() < this.jobExecutionHour; } } protected  FixedHourScheduledJob(Clock clock, int jobExecutionHour); @Override final boolean shouldExecute(LocalDateTime lastExecuteTime);  }