Skip to content

Commit 067e8f8

Browse files
committed
Add example with eventually
1 parent 580139f commit 067e8f8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

logcapture-kotest/src/test/kotlin/org/logcapture/kotest/LogCaptureListenerSpec.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.logcapture.kotest
22

3+
import io.kotest.assertions.timing.eventually
34
import io.kotest.core.spec.style.StringSpec
45
import org.logcapture.assertion.ExpectedLoggingMessage.aLog
56
import org.slf4j.Logger
67
import org.slf4j.LoggerFactory
8+
import kotlin.time.Duration.Companion.seconds
79

810
class LogCaptureListenerSpec : StringSpec({
911

@@ -24,4 +26,20 @@ class LogCaptureListenerSpec : StringSpec({
2426

2527
logCaptureListener.logged(aLog().info().withMessage("a message"), 2)
2628
}
29+
30+
"use eventually to verify logs" {
31+
var i = 0
32+
eventually(1.seconds) {
33+
i += 1
34+
logMessageWhenCondition(log, i == 5)
35+
logCaptureListener.logged(aLog().info().withMessage("a message"))
36+
}
37+
}
2738
})
39+
40+
fun logMessageWhenCondition(log: Logger, condition: Boolean) {
41+
if (condition) {
42+
log.info("a message")
43+
}
44+
}
45+

0 commit comments

Comments
 (0)