-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly mock Instant.now to fix test flakiness
Signed-off-by: Antoine MAZEAS <[email protected]>
- Loading branch information
1 parent
c9e3e73
commit e83485c
Showing
2 changed files
with
132 additions
and
65 deletions.
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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package io.openbas.utils.fixtures; | ||
|
||
import static java.time.Instant.now; | ||
import static java.time.temporal.ChronoUnit.MINUTES; | ||
|
||
import io.openbas.database.model.Exercise; | ||
|
@@ -37,18 +36,26 @@ public static Exercise createDefaultCrisisExercise() { | |
} | ||
|
||
public static Exercise createDefaultIncidentResponseExercise() { | ||
return createDefaultIncidentResponseExercise(Instant.now()); | ||
} | ||
|
||
public static Exercise createDefaultIncidentResponseExercise(Instant startTime) { | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Incident response exercise"); | ||
exercise.setDescription("An incident response exercise for my enterprise"); | ||
exercise.setSubtitle("An incident response exercise"); | ||
exercise.setFrom("[email protected]"); | ||
exercise.setCategory("incident-response"); | ||
exercise.setStatus(ExerciseStatus.SCHEDULED); | ||
exercise.setStart(Instant.now()); | ||
exercise.setStart(startTime); | ||
return exercise; | ||
} | ||
|
||
public static Exercise createDefaultAttackExercise() { | ||
return createDefaultAttackExercise(Instant.now()); | ||
} | ||
|
||
public static Exercise createDefaultAttackExercise(Instant startTime) { | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Draft incident response exercise"); | ||
exercise.setDescription("An incident response exercise for my enterprise"); | ||
|
@@ -57,11 +64,15 @@ public static Exercise createDefaultAttackExercise() { | |
exercise.setCategory("attack-scenario"); | ||
exercise.setMainFocus("incident-response"); | ||
exercise.setStatus(ExerciseStatus.SCHEDULED); | ||
exercise.setStart(Instant.now()); | ||
exercise.setStart(startTime); | ||
return exercise; | ||
} | ||
|
||
public static Exercise createRunningAttackExercise() { | ||
return createRunningAttackExercise(Instant.now()); | ||
} | ||
|
||
public static Exercise createRunningAttackExercise(Instant startTime) { | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Draft incident response exercise"); | ||
exercise.setDescription("An incident response exercise for my enterprise"); | ||
|
@@ -70,11 +81,15 @@ public static Exercise createRunningAttackExercise() { | |
exercise.setCategory("attack-scenario"); | ||
exercise.setMainFocus("incident-response"); | ||
exercise.setStatus(ExerciseStatus.RUNNING); | ||
exercise.setStart(Instant.now()); | ||
exercise.setStart(startTime); | ||
return exercise; | ||
} | ||
|
||
public static Exercise createCanceledAttackExercise() { | ||
return createCanceledAttackExercise(Instant.now()); | ||
} | ||
|
||
public static Exercise createCanceledAttackExercise(Instant startTime) { | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Draft incident response exercise"); | ||
exercise.setDescription("An incident response exercise for my enterprise"); | ||
|
@@ -83,11 +98,15 @@ public static Exercise createCanceledAttackExercise() { | |
exercise.setCategory("attack-scenario"); | ||
exercise.setMainFocus("incident-response"); | ||
exercise.setStatus(ExerciseStatus.CANCELED); | ||
exercise.setStart(Instant.now()); | ||
exercise.setStart(startTime); | ||
return exercise; | ||
} | ||
|
||
public static Exercise createFinishedAttackExercise() { | ||
return createFinishedAttackExercise(Instant.now()); | ||
} | ||
|
||
public static Exercise createFinishedAttackExercise(Instant startTime) { | ||
Exercise exercise = new Exercise(); | ||
exercise.setName("Draft incident response exercise"); | ||
exercise.setDescription("An incident response exercise for my enterprise"); | ||
|
@@ -96,21 +115,25 @@ public static Exercise createFinishedAttackExercise() { | |
exercise.setCategory("attack-scenario"); | ||
exercise.setMainFocus("incident-response"); | ||
exercise.setStatus(ExerciseStatus.FINISHED); | ||
exercise.setStart(Instant.now()); | ||
exercise.setStart(startTime); | ||
return exercise; | ||
} | ||
|
||
public static Exercise createPausedAttackExercise() { | ||
return createPausedAttackExercise(Instant.now()); | ||
} | ||
|
||
public static Exercise createPausedAttackExercise(Instant startTime) { | ||
Exercise exercise = new Exercise(); | ||
exercise.setCurrentPause(now().truncatedTo(MINUTES).minus(1, MINUTES)); | ||
exercise.setCurrentPause(startTime.truncatedTo(MINUTES).minus(1, MINUTES)); | ||
exercise.setName("Draft incident response exercise"); | ||
exercise.setDescription("An incident response exercise for my enterprise"); | ||
exercise.setSubtitle("An incident response exercise"); | ||
exercise.setFrom("[email protected]"); | ||
exercise.setCategory("attack-scenario"); | ||
exercise.setMainFocus("incident-response"); | ||
exercise.setStatus(ExerciseStatus.PAUSED); | ||
exercise.setStart(Instant.now()); | ||
exercise.setStart(startTime); | ||
return exercise; | ||
} | ||
} |