@Test public void testSetAlarmInvalid() { assertThrows(IllegalArgumentException.class, () -> this.acl.setAlarm(1, 12, 60)); assertThrows(IllegalArgumentException.class, () -> this.acl.setAlarm(1, 24, 40)); }
protected Alarm setAlarm(int tomorrow, int hour, int minute) { if (Alarm.timeValid(hour, minute)) { tomorrowCheck(tomorrow, hour, minute); int id = searchAlarmId(); Alarm alarm = new Alarm(id, this.alarmTime, true); this.alarmStorage.save(alarm); Runnable alarmRunnable = createAlarmRunnable(id); ZonedDateTime with = this.environment.getCurrentDateTime().with(alarm.getAlarmTime()); if (with.isBefore(this.environment.getCurrentDateTime())) { with = with.plusDays(1); } this.taskScheduler.schedule(alarmRunnable, with.toInstant()); return alarm; } throw new IllegalArgumentException(); }
AlarmClockLogic implements RunnableService { protected Alarm setAlarm(int tomorrow, int hour, int minute) { if (Alarm.timeValid(hour, minute)) { tomorrowCheck(tomorrow, hour, minute); int id = searchAlarmId(); Alarm alarm = new Alarm(id, this.alarmTime, true); this.alarmStorage.save(alarm); Runnable alarmRunnable = createAlarmRunnable(id); ZonedDateTime with = this.environment.getCurrentDateTime().with(alarm.getAlarmTime()); if (with.isBefore(this.environment.getCurrentDateTime())) { with = with.plusDays(1); } this.taskScheduler.schedule(alarmRunnable, with.toInstant()); return alarm; } throw new IllegalArgumentException(); } }
AlarmClockLogic implements RunnableService { protected Alarm setAlarm(int tomorrow, int hour, int minute) { if (Alarm.timeValid(hour, minute)) { tomorrowCheck(tomorrow, hour, minute); int id = searchAlarmId(); Alarm alarm = new Alarm(id, this.alarmTime, true); this.alarmStorage.save(alarm); Runnable alarmRunnable = createAlarmRunnable(id); ZonedDateTime with = this.environment.getCurrentDateTime().with(alarm.getAlarmTime()); if (with.isBefore(this.environment.getCurrentDateTime())) { with = with.plusDays(1); } this.taskScheduler.schedule(alarmRunnable, with.toInstant()); return alarm; } throw new IllegalArgumentException(); }  }
AlarmClockLogic implements RunnableService { protected Alarm setAlarm(int tomorrow, int hour, int minute) { if (Alarm.timeValid(hour, minute)) { tomorrowCheck(tomorrow, hour, minute); int id = searchAlarmId(); Alarm alarm = new Alarm(id, this.alarmTime, true); this.alarmStorage.save(alarm); Runnable alarmRunnable = createAlarmRunnable(id); ZonedDateTime with = this.environment.getCurrentDateTime().with(alarm.getAlarmTime()); if (with.isBefore(this.environment.getCurrentDateTime())) { with = with.plusDays(1); } this.taskScheduler.schedule(alarmRunnable, with.toInstant()); return alarm; } throw new IllegalArgumentException(); }  String stopRinging(); @Override void start(); @Override void stop(); }
AlarmClockLogic implements RunnableService { protected Alarm setAlarm(int tomorrow, int hour, int minute) { if (Alarm.timeValid(hour, minute)) { tomorrowCheck(tomorrow, hour, minute); int id = searchAlarmId(); Alarm alarm = new Alarm(id, this.alarmTime, true); this.alarmStorage.save(alarm); Runnable alarmRunnable = createAlarmRunnable(id); ZonedDateTime with = this.environment.getCurrentDateTime().with(alarm.getAlarmTime()); if (with.isBefore(this.environment.getCurrentDateTime())) { with = with.plusDays(1); } this.taskScheduler.schedule(alarmRunnable, with.toInstant()); return alarm; } throw new IllegalArgumentException(); }  String stopRinging(); @Override void start(); @Override void stop();  }