public void schedule(final ScheduledHealthCheck check, final boolean healthy) {
        unschedule(check.getName());

        final Duration interval;
        if (healthy) {
            interval = check.getSchedule().getCheckInterval();
        } else {
            interval = check.getSchedule().getDowntimeInterval();
        }

        schedule(check, interval, interval);
    }
@Test
    void shouldRescheduleCheckForUnhealthyDependency() {
        final String name = "test";
        final Schedule schedule = new Schedule();
        final ScheduledFuture future = mock(ScheduledFuture.class);

        when(future.cancel(true)).thenReturn(true);

        final ScheduledHealthCheck check = mock(ScheduledHealthCheck.class);
        when(check.getName()).thenReturn(name);
        when(check.getSchedule()).thenReturn(schedule);

        when(executor.scheduleWithFixedDelay(
            eq(check),
            or(eq(schedule.getCheckInterval().toMilliseconds()), eq(schedule.getDowntimeInterval().toMilliseconds())),
            or(eq(schedule.getCheckInterval().toMilliseconds()), eq(schedule.getDowntimeInterval().toMilliseconds())),
            eq(TimeUnit.MILLISECONDS))
        )
            .thenReturn(future);

        scheduler.schedule(check, true);

        scheduler.schedule(check, false);

        verify(executor, times(2)).scheduleWithFixedDelay(
            eq(check),
            or(eq(schedule.getCheckInterval().toMilliseconds()), eq(schedule.getDowntimeInterval().toMilliseconds())),
            or(eq(schedule.getCheckInterval().toMilliseconds()), eq(schedule.getDowntimeInterval().toMilliseconds())),
            eq(TimeUnit.MILLISECONDS));

        verify(future).cancel(true);
    }