merge with 2.0.0-m3

This commit is contained in:
Sebastian Sdorra
2019-06-25 09:53:44 +02:00
45 changed files with 246 additions and 159 deletions

View File

@@ -53,7 +53,7 @@ class CronTaskTest {
@Test
void shouldCancelWithoutNextRun() {
ZonedDateTime time = ZonedDateTime.now();
when(expression.calculateNextRun()).thenAnswer(new FirstTimeAnswer(Optional.of(time), Optional.empty()));
when(expression.calculateNextRun()).thenReturn(Optional.of(time), Optional.empty());
when(expression.shouldRun(time)).thenReturn(true);
CronTask task = task();
@@ -64,32 +64,26 @@ class CronTaskTest {
verify(future).cancel(false);
}
@Test
void shouldNotRunAfterCancelHasBeenCalledIfRunIsCalledAgain() {
ZonedDateTime time = ZonedDateTime.now();
when(expression.calculateNextRun()).thenReturn(Optional.of(time), Optional.empty());
when(expression.shouldRun(time)).thenReturn(true);
CronTask task = task();
task.setFuture(future);
task.run();
task.run();
verify(future).cancel(false);
verify(runnable).run();
}
@Test
void shouldNotRun() {
task().run();
verify(runnable, never()).run();
}
private static class FirstTimeAnswer implements Answer<Object> {
private boolean first = true;
private final Object answer;
private final Object secondAnswer;
FirstTimeAnswer(Object answer, Object secondAnswer) {
this.answer = answer;
this.secondAnswer = secondAnswer;
}
@Override
public Object answer(InvocationOnMock invocation) {
if (first) {
first = false;
return answer;
}
return secondAnswer;
}
}
}