Skip to content

Conversation

@snowykte0426
Copy link
Contributor

Summary

This PR addresses issue #4008 by refactoring ReplyingKafkaTemplateTests
to improve test maintainability and readability through better
separation of concerns.

  • Refactored listener methods to return Message<?> objects instead of
    handling validation internally
  • Extracted header validation logic into separate utility methods
    (validateHeaders, validateSuccessfulResponse)
  • Simplified test methods by moving validation concerns outside of
    listener logic

Changes Made

  • Listener Methods: Simplified
    handleCustomReplyHeaderNoReplyPartition and
    handleCustomReplyHeaderDefaultPartitionHeader to focus only on business
    logic
  • Validation Utilities: Added validateHeaders() and
    validateSuccessfulResponse() methods for external header verification
  • Test Methods: Updated testCustomReplyTopicHeaderIsNotDuplicated
    and testCustomReplyHeadersAreNotDuplicated to use the new validation
    approach

Fixes #4008

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for refactoring this hard-to-read logic!


assertThat(resultingMessage.getPayload()).isEqualTo("OK");
assertThat(resultingMessage.getHeaders()).containsKey("originalPayload");
assertThat(resultingMessage.getHeaders().get("originalPayload")).isEqualTo("expected_message");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an API in AssertJ to do both at the same time:

assertThat(resultingMessage.getHeaders()).containsEntry("originalPayload", "expected_message");

Copy link
Contributor Author

@snowykte0426 snowykte0426 Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an API in AssertJ to do both at the same time:

assertThat(resultingMessage.getHeaders()).containsEntry("originalPayload", "expected_message");

@artembilan Thank you for the suggestion! I’ve implemented your feedback in commit e8baed9 by using AssertJ’s containsEntry() method. This replaces the separate assertions with the more concise approach you recommended.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update!
It is really very close to merge.
However I’ve noticed the problem:

Signed-off-by: snowykte0426 snowykte0426@naver.com

this one has to come with your official name to satisfy all the legal requirements.
Please, revise your local Git client config.
Squash and push a commit with with right sign-off.

Improve test validation logic by:
- Using direct assertThat() assertions instead of custom validation methods
- Replacing separate header assertions with single containsEntry() method
- Fixing checkstyle violations (trailing whitespace and extra blank lines)

Signed-off-by: Kim Tae Eun <snowykte0426@naver.com>
@snowykte0426
Copy link
Contributor Author

Thank you for the update! It is really very close to merge. However I’ve noticed the problem:

Signed-off-by: snowykte0426 snowykte0426@naver.com

this one has to come with your official name to satisfy all the legal requirements. Please, revise your local Git client config. Squash and push a commit with with right sign-off.

Thank you for the review feedback. I've squashed the commits and updated
the Signed-off-by with my official name as requested (commit b965e86).

@artembilan artembilan merged commit 952f231 into spring-projects:main Aug 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test improvement in ReplyingKafkaTemplateTests

2 participants