-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add convenience factory methods to JobSchedule (#134)
* Add convenience factory methods to JobSchedule * Add ofIntervalDelay factory methods to JobSchedule; one accepts a io.dropwizard.Duration and the other accepts a java.time.Duration Closes #133
- Loading branch information
1 parent
8da59e2
commit d1d6bd8
Showing
2 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/org/kiwiproject/dropwizard/util/config/JobScheduleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.kiwiproject.dropwizard.util.config; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
|
||
import io.dropwizard.util.Duration; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@DisplayName("JobSchedule") | ||
class JobScheduleTest { | ||
|
||
@Nested | ||
class OfIntervalDelay { | ||
|
||
public static final int SECONDS = 45; | ||
|
||
@Test | ||
void shouldNotPermitNullDropwizardDuration() { | ||
assertThatIllegalArgumentException().isThrownBy(() -> | ||
JobSchedule.ofIntervalDelay((Duration) null)) | ||
.withMessage("intervalDelay must not be null"); | ||
} | ||
|
||
@Test | ||
void shouldCreateInstanceWithDropwizardDuration() { | ||
var jobSchedule = JobSchedule.ofIntervalDelay(Duration.seconds(SECONDS)); | ||
|
||
assertThat(jobSchedule.getInitialDelay()).isEqualTo(JobSchedule.DEFAULT_INITIAL_DELAY); | ||
assertThat(jobSchedule.getIntervalDelay().toSeconds()).isEqualTo(SECONDS); | ||
} | ||
|
||
@Test | ||
void shouldNotPermitNullJavaTimeDuration() { | ||
assertThatIllegalArgumentException().isThrownBy(() -> | ||
JobSchedule.ofIntervalDelay((java.time.Duration) null)) | ||
.withMessage("intervalDelay must not be null"); | ||
} | ||
|
||
@Test | ||
void shouldCreateInstanceWithJavaTimeDuration() { | ||
var jobSchedule = JobSchedule.ofIntervalDelay(java.time.Duration.ofSeconds(SECONDS)); | ||
|
||
assertThat(jobSchedule.getInitialDelay()).isEqualTo(JobSchedule.DEFAULT_INITIAL_DELAY); | ||
assertThat(jobSchedule.getIntervalDelay().toSeconds()).isEqualTo(SECONDS); | ||
} | ||
} | ||
} |