35 lines
1.0 KiB
Kotlin
35 lines
1.0 KiB
Kotlin
package eventDemo.libs.command
|
|
|
|
import eventDemo.testHelpers.spyPing
|
|
import io.kotest.core.spec.style.FunSpec
|
|
import org.junit.jupiter.api.assertThrows
|
|
import kotlin.time.Duration.Companion.seconds
|
|
|
|
class CommandUnicityCheckerTest :
|
|
FunSpec({
|
|
test("runOnlyOnce must run all commands") {
|
|
spyPing(exactly = 2, duration = 3.seconds) { ping ->
|
|
val com1 = CommandForTest(CommandId())
|
|
val com2 = CommandForTest(CommandId())
|
|
CommandUnicityChecker<CommandForTest>().run {
|
|
runOnlyOnce(com1) { ping() }
|
|
runOnlyOnce(com2) { ping() }
|
|
}
|
|
}
|
|
}
|
|
|
|
test("runOnlyOnce") {
|
|
spyPing(exactly = 2, duration = 3.seconds) { ping ->
|
|
val com1 = CommandForTest(CommandId())
|
|
val com2 = CommandForTest(CommandId())
|
|
CommandUnicityChecker<CommandForTest>().run {
|
|
runOnlyOnce(com1) { ping() }
|
|
runOnlyOnce(com2) { ping() }
|
|
assertThrows<CommandUnicityChecker.UnicityException> {
|
|
runOnlyOnce(com2) { ping() }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|