@Test
 public void shouldScheduleDailyJob() {
   pillRegimen = new PillRegimen(externalId, dosages, new DailyScheduleDetails(15, 2));
   pillRegimen.setId(pillRegimenId);
   jobScheduler.scheduleDailyJob(pillRegimen);
   verify(schedulerService, times(2)).scheduleJob(any(CronSchedulableJob.class));
 }
  @Test
  public void shouldSetUpCorrectCronExpressionForDailyJob() {
    final LocalDate today = DateUtil.today();
    pillRegimen = new PillRegimen(externalId, dosages, new DailyScheduleDetails(15, 2));
    pillRegimen.setId(pillRegimenId);
    final HashSet<Medicine> medicines =
        new HashSet<Medicine>() {
          {
            add(new Medicine("med1", today.minusDays(1), null));
          }
        };
    final Dosage dosage1 = new Dosage(new Time(10, 5), medicines);

    jobScheduler =
        new PillRegimenJobScheduler(schedulerService) {
          @Override
          public CronSchedulableJob getSchedulableDailyJob(
              String pillRegimenId, String externalId, Dosage dosage) {
            return super.getSchedulableDailyJob(pillRegimenId, externalId, dosage);
          }
        };

    final CronSchedulableJob schedulableJob =
        jobScheduler.getSchedulableDailyJob(pillRegimenId, externalId, dosage1);
    assertEquals(String.format("0 %d %d * * ?", 5, 10), schedulableJob.getCronExpression());
    assertEquals(
        EventKeys.PILLREMINDER_REMINDER_EVENT_SUBJECT_SCHEDULER,
        schedulableJob.getMotechEvent().getSubject());
    assertTrue(schedulableJob.getStartTime().getTime() > today.minusDays(1).toDate().getTime());
  }
 @Test
 public void shouldUnscheduleJob() {
   pillRegimen = new PillRegimen(externalId, dosages, new DailyScheduleDetails(15, 2));
   pillRegimen.setId(pillRegimenId);
   jobScheduler.unscheduleJobs(pillRegimen);
   verify(schedulerService, times(1))
       .unscheduleJob(EventKeys.PILLREMINDER_REMINDER_EVENT_SUBJECT_SCHEDULER, "dosage1");
   verify(schedulerService, times(1))
       .unscheduleRepeatingJob(EventKeys.PILLREMINDER_REMINDER_EVENT_SUBJECT_SCHEDULER, "dosage1");
   verify(schedulerService, times(1))
       .unscheduleJob(EventKeys.PILLREMINDER_REMINDER_EVENT_SUBJECT_SCHEDULER, "dosage2");
   verify(schedulerService, times(1))
       .unscheduleRepeatingJob(EventKeys.PILLREMINDER_REMINDER_EVENT_SUBJECT_SCHEDULER, "dosage2");
 }