Skip to content

Commit a4b2016

Browse files
adinauerclaude
andcommitted
test(spring): Address Kafka review comments
Simplify Spring Kafka test interceptors and cover intercepting records without a consumer. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e4725b8 commit a4b2016

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

sentry-spring/src/test/kotlin/io/sentry/spring/kafka/SentryKafkaConsumerBeanPostProcessorTest.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.sentry.spring.kafka
33
import kotlin.test.Test
44
import kotlin.test.assertSame
55
import kotlin.test.assertTrue
6-
import org.apache.kafka.clients.consumer.ConsumerRecord
76
import org.mockito.kotlin.mock
87
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory
98
import org.springframework.kafka.core.ConsumerFactory
@@ -64,12 +63,7 @@ class SentryKafkaConsumerBeanPostProcessorTest {
6463
val factory = ConcurrentKafkaListenerContainerFactory<String, String>()
6564
factory.consumerFactory = consumerFactory
6665

67-
val customerInterceptor =
68-
object : RecordInterceptor<String, String> {
69-
override fun intercept(
70-
record: ConsumerRecord<String, String>
71-
): ConsumerRecord<String, String>? = record
72-
}
66+
val customerInterceptor = RecordInterceptor<String, String> { record -> record }
7367
factory.setRecordInterceptor(customerInterceptor)
7468

7569
val processor = SentryKafkaConsumerBeanPostProcessor()
@@ -97,12 +91,7 @@ class SentryKafkaConsumerBeanPostProcessorTest {
9791
val consumerFactory = mock<ConsumerFactory<String, String>>()
9892
val factory = ConcurrentKafkaListenerContainerFactory<String, String>()
9993
factory.consumerFactory = consumerFactory
100-
val customerInterceptor =
101-
object : RecordInterceptor<String, String> {
102-
override fun intercept(
103-
record: ConsumerRecord<String, String>
104-
): ConsumerRecord<String, String>? = record
105-
}
94+
val customerInterceptor = RecordInterceptor<String, String> { record -> record }
10695
factory.setRecordInterceptor(customerInterceptor)
10796

10897
val field = factory.javaClass.superclass.getDeclaredField("recordInterceptor")

sentry-spring/src/test/kotlin/io/sentry/spring/kafka/SentryKafkaRecordInterceptorTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,19 @@ class SentryKafkaRecordInterceptorTest {
269269
verify(delegate).intercept(record, consumer)
270270
}
271271

272+
@Test
273+
fun `delegates to existing interceptor when consumer is null`() {
274+
val delegate = mock<RecordInterceptor<String, String>>()
275+
val record = createRecord()
276+
whenever(delegate.intercept(record)).thenReturn(record)
277+
278+
val interceptor = SentryKafkaRecordInterceptor(scopes, delegate)
279+
val result = interceptor.intercept(record)
280+
281+
assertEquals(record, result)
282+
verify(delegate).intercept(record)
283+
}
284+
272285
@Test
273286
fun `success finishes transaction and delegates`() {
274287
val delegate = mock<RecordInterceptor<String, String>>()

0 commit comments

Comments
 (0)