@Test protected void testReactivateTimerNotValid() { List<Timer> returnedTimers = createTimers(3, true); when(this.timerStorage.getAll()).thenReturn(returnedTimers); when(this.env.getCurrentDateTime()).thenReturn(ZonedDateTime.of(2018, 2, 1, 4, 21, 55, 987, ZoneId.of("Z"))); assertThrows(IllegalArgumentException.class, () -> this.tlogic.reactivateTimer(returnedTimers.get(2))); }
public Timer reactivateTimer(Timer timer) { if (!timer.isActive()) { timer.setActive(true); LocalDateTime current = LocalDateTime.now(); int timertime = (int) (timer.duration().toMillis() / 1000); LocalDateTime newTimerTime = current.plusSeconds(timertime); timer.setTimerTime(newTimerTime); this.timerStorage.save(timer); Runnable timerRunnable = createTimerRunnable(timer); ZonedDateTime ringtime = this.environment.getCurrentDateTime().with(timer.getTimerTime()); this.taskScheduler.schedule(timerRunnable, ringtime.toInstant()); return timer; } throw new IllegalArgumentException("Timer is already active"); }
TimerLogic implements RunnableService { public Timer reactivateTimer(Timer timer) { if (!timer.isActive()) { timer.setActive(true); LocalDateTime current = LocalDateTime.now(); int timertime = (int) (timer.duration().toMillis() / 1000); LocalDateTime newTimerTime = current.plusSeconds(timertime); timer.setTimerTime(newTimerTime); this.timerStorage.save(timer); Runnable timerRunnable = createTimerRunnable(timer); ZonedDateTime ringtime = this.environment.getCurrentDateTime().with(timer.getTimerTime()); this.taskScheduler.schedule(timerRunnable, ringtime.toInstant()); return timer; } throw new IllegalArgumentException("Timer is already active"); } }
TimerLogic implements RunnableService { public Timer reactivateTimer(Timer timer) { if (!timer.isActive()) { timer.setActive(true); LocalDateTime current = LocalDateTime.now(); int timertime = (int) (timer.duration().toMillis() / 1000); LocalDateTime newTimerTime = current.plusSeconds(timertime); timer.setTimerTime(newTimerTime); this.timerStorage.save(timer); Runnable timerRunnable = createTimerRunnable(timer); ZonedDateTime ringtime = this.environment.getCurrentDateTime().with(timer.getTimerTime()); this.taskScheduler.schedule(timerRunnable, ringtime.toInstant()); return timer; } throw new IllegalArgumentException("Timer is already active"); }  }
TimerLogic implements RunnableService { public Timer reactivateTimer(Timer timer) { if (!timer.isActive()) { timer.setActive(true); LocalDateTime current = LocalDateTime.now(); int timertime = (int) (timer.duration().toMillis() / 1000); LocalDateTime newTimerTime = current.plusSeconds(timertime); timer.setTimerTime(newTimerTime); this.timerStorage.save(timer); Runnable timerRunnable = createTimerRunnable(timer); ZonedDateTime ringtime = this.environment.getCurrentDateTime().with(timer.getTimerTime()); this.taskScheduler.schedule(timerRunnable, ringtime.toInstant()); return timer; } throw new IllegalArgumentException("Timer is already active"); }  Runnable createTimerRunnable(Timer timer); Timer setTimer(LocalDateTime timerTime); int searchTimerId(); String deleteAllTimers(); String deleteTimer(int timerNumber); String stopRinging(); Timer getTimer(int timerNumber); List<Timer> getAllTimers(); Timer pauseTimer(Timer timer); Timer reactivateTimer(Timer timer); @Override void start(); @Override void stop(); }
TimerLogic implements RunnableService { public Timer reactivateTimer(Timer timer) { if (!timer.isActive()) { timer.setActive(true); LocalDateTime current = LocalDateTime.now(); int timertime = (int) (timer.duration().toMillis() / 1000); LocalDateTime newTimerTime = current.plusSeconds(timertime); timer.setTimerTime(newTimerTime); this.timerStorage.save(timer); Runnable timerRunnable = createTimerRunnable(timer); ZonedDateTime ringtime = this.environment.getCurrentDateTime().with(timer.getTimerTime()); this.taskScheduler.schedule(timerRunnable, ringtime.toInstant()); return timer; } throw new IllegalArgumentException("Timer is already active"); }  Runnable createTimerRunnable(Timer timer); Timer setTimer(LocalDateTime timerTime); int searchTimerId(); String deleteAllTimers(); String deleteTimer(int timerNumber); String stopRinging(); Timer getTimer(int timerNumber); List<Timer> getAllTimers(); Timer pauseTimer(Timer timer); Timer reactivateTimer(Timer timer); @Override void start(); @Override void stop();  }