@@ -4,27 +4,38 @@ import ch.qos.logback.access.common.spi.AccessContext
44import ch.qos.logback.core.spi.FilterReply
55import ch.qos.logback.core.status.ErrorStatus
66import ch.qos.logback.core.status.StatusManager
7+ import io.kotest.matchers.shouldBe
78import io.mockk.every
89import io.mockk.mockk
10+ import io.mockk.slot
911import io.mockk.verify
1012import org.junit.jupiter.api.Test
13+ import org.junit.jupiter.params.ParameterizedTest
14+ import org.junit.jupiter.params.provider.EnumSource
1115import reactor.netty.http.server.logging.AccessLogArgProvider
1216
1317class 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