Skip to content

Commit c6c02ad

Browse files
committed
Polish documentation and test code
- Improve Javadoc clarity with technical explanation for method constraints - Remove redundant phrase from BatchMessagingMessageConverter documentation - Generalize test class description for future extensibility - Clean up test assertions by removing redundant size checks - Use descriptive variable names in test data Signed-off-by: Jujuwryy <[email protected]>
1 parent 3b3f910 commit c6c02ad

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/BatchMessagingMessageListenerAdapter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@ public void setBatchToRecordAdapter(BatchToRecordAdapter<K, V> batchToRecordAdap
117117
* properly propagated to the batch converter's record converter for message conversion
118118
* in batch listeners.
119119
* <p>
120-
* Uses the same validation as the parent class to prevent the paradox of choice:
121-
* not allowed when a custom {@link #setBatchMessageConverter(BatchMessageConverter)
122-
* batchMessageConverter} is provided. Since {@link BatchMessagingMessageConverter} now
120+
* This method cannot be called after {@link #setBatchMessageConverter(BatchMessageConverter)
121+
* setBatchMessageConverter()} as it would cause a mutation of the internal
122+
* batchMessageConverter. Instead, the SmartMessageConverter has to be provided on the
123+
* external BatchMessageConverter. Since {@link BatchMessagingMessageConverter} now
123124
* always has a default {@link org.springframework.kafka.support.converter.MessagingMessageConverter},
124125
* users can configure the converter via the annotation without needing to set it on the factory.
125126
* @param messageConverter the converter to set

spring-kafka/src/main/java/org/springframework/kafka/support/converter/BatchMessagingMessageConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public RecordMessageConverter getRecordMessageConverter() {
146146
}
147147

148148
/**
149-
* Set a spring-messaging {@link SmartMessageConverter} to convert the record value to
149+
* Set a {@link SmartMessageConverter} to convert the record value to
150150
* the desired type.
151151
* @param messagingConverter the converter.
152152
* @since 3.3.11

spring-kafka/src/test/java/org/springframework/kafka/listener/BatchSmartMessageConverterTests.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555

5656
/**
5757
* Integration tests for SmartMessageConverter support in batch listeners.
58-
* Reproduces and verifies the fix for the issue described in GH-4097.
5958
*
6059
* @author George Mahfoud
6160
* @since 3.3.11
@@ -80,7 +79,7 @@ void testContentTypeConverterWithBatchListener() throws Exception {
8079
this.template.send("smartBatchTopic", "world".getBytes());
8180

8281
assertThat(listener.latch.await(10, TimeUnit.SECONDS)).isTrue();
83-
assertThat(listener.received).hasSize(2).containsExactly("hello", "world");
82+
assertThat(listener.received).containsExactly("hello", "world");
8483
}
8584

8685
@Test
@@ -90,13 +89,15 @@ void testMultipleListenersWithDifferentConverters() throws Exception {
9089
listener1.reset(1);
9190
listener2.reset(1);
9291

93-
this.template.send("smartBatchTopic", "foo".getBytes());
94-
this.template.send("smartBatchTopic2", "bar".getBytes());
92+
String listener1Data = "listener1Data";
93+
String listener2Data = "listener2Data";
94+
this.template.send("smartBatchTopic", listener1Data.getBytes());
95+
this.template.send("smartBatchTopic2", listener2Data.getBytes());
9596

9697
assertThat(listener1.latch.await(10, TimeUnit.SECONDS)).isTrue();
9798
assertThat(listener2.latch.await(10, TimeUnit.SECONDS)).isTrue();
98-
assertThat(listener1.received).hasSize(1).containsExactly("foo");
99-
assertThat(listener2.received).hasSize(1).containsExactly("BAR");
99+
assertThat(listener1.received).containsExactly(listener1Data);
100+
assertThat(listener2.received).containsExactly(listener2Data.toUpperCase());
100101
}
101102

102103
@Configuration

0 commit comments

Comments
 (0)