Skip to content

Commit 0027f2d

Browse files
committed
Improve AccessLogTests
Signed-off-by: Dmitry Sulman <[email protected]>
1 parent 8127776 commit 0027f2d

File tree

1 file changed

+16
-5
lines changed
  • logback-access-reactor-netty/src/test/kotlin/io/github/dmitrysulman/logback/access/reactor/netty

1 file changed

+16
-5
lines changed

logback-access-reactor-netty/src/test/kotlin/io/github/dmitrysulman/logback/access/reactor/netty/AccessLogTests.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,38 @@ import ch.qos.logback.access.common.spi.AccessContext
44
import ch.qos.logback.core.spi.FilterReply
55
import ch.qos.logback.core.status.ErrorStatus
66
import ch.qos.logback.core.status.StatusManager
7+
import io.kotest.matchers.shouldBe
78
import io.mockk.every
89
import io.mockk.mockk
10+
import io.mockk.slot
911
import io.mockk.verify
1012
import org.junit.jupiter.api.Test
13+
import org.junit.jupiter.params.ParameterizedTest
14+
import org.junit.jupiter.params.provider.EnumSource
1115
import reactor.netty.http.server.logging.AccessLogArgProvider
1216

1317
class AccessLogTests {
14-
@Test
15-
fun `log() method should call accessContext#callAppenders`() {
18+
@ParameterizedTest
19+
@EnumSource(value = FilterReply::class, names = ["DENY"], mode = EnumSource.Mode.EXCLUDE)
20+
fun `log() method should call accessContext#callAppenders`(filterReply: FilterReply) {
1621
val mockContext = mockk<AccessContext>(relaxed = true)
1722
val mockArgProvider = mockk<AccessLogArgProvider>(relaxed = true)
23+
val accessEventCaptor = slot<AccessEvent>()
24+
every { mockContext.getFilterChainDecision(any()) } returns filterReply
1825

1926
val accessLog = AccessLog(mockContext, mockArgProvider)
2027
accessLog.log()
2128

22-
verify(exactly = 1) { mockContext.getFilterChainDecision(any()) }
23-
verify(exactly = 1) { mockContext.callAppenders(any()) }
29+
verify(exactly = 1) { mockArgProvider.duration() }
30+
verify(exactly = 1) { mockContext.sequenceNumberGenerator }
31+
verify(exactly = 1) { mockContext.getFilterChainDecision(capture(accessEventCaptor)) }
32+
verify(exactly = 1) { mockContext.callAppenders(accessEventCaptor.captured) }
33+
34+
accessEventCaptor.captured.threadName shouldBe Thread.currentThread().name
2435
}
2536

2637
@Test
27-
fun `log() method should not call accessContext#callAppenders if mockContext#getFilterChainDecision returns false`() {
38+
fun `log() method should not call accessContext#callAppenders if getFilterChainDecision returns DENY`() {
2839
val mockContext = mockk<AccessContext>(relaxed = true)
2940
val mockArgProvider = mockk<AccessLogArgProvider>(relaxed = true)
3041
every { mockContext.getFilterChainDecision(any()) } returns FilterReply.DENY

0 commit comments

Comments
 (0)