Skip to content

Conversation

@mjd507
Copy link
Contributor

@mjd507 mjd507 commented May 6, 2025

No description provided.

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.

This is huge, @mjd507 !
Thank you very much!

Honestly, all my review is just nit-pick and we simply can accept your changes as is.
Those are just recommendations for the future.
Let me know if you are going to address them or let's move on for other more important tasks!

I wonder if you automated such a migration somehow or what 😄

MultipleAnnotationTestBean bean = new MultipleAnnotationTestBean();
new MethodInvokingMessageGroupProcessor(bean);
assertThatThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean))
.isInstanceOf(IllegalArgumentException.class);
Copy link
Member

Choose a reason for hiding this comment

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

We prefer an API like this:

assertThatIllegalArgumentException().isThrownBy();

instead.


NoPublicMethodTestBean bean = new NoPublicMethodTestBean();
new MethodInvokingMessageGroupProcessor(bean);
assertThatThrownBy(() -> new MethodInvokingMessageGroupProcessor(bean))
Copy link
Member

Choose a reason for hiding this comment

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

Similar here:

assertThatIllegalStateException()

QueueChannel[] channels = new QueueChannel[0];
new ChannelPurger(channels);
assertThatThrownBy(() -> new ChannelPurger(channels))
.isInstanceOf(IllegalArgumentException.class);
Copy link
Member

Choose a reason for hiding this comment

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

Don't miss, please, to address this class changes in favor of assertThatIllegalArgumentException().

public void unsupportedTypeAndNoConversionService() {
MessageChannel channel = createChannel(Integer.class);
channel.send(new GenericMessage<String>("123"));
assertThatThrownBy(() -> channel.send(new GenericMessage<String>("123")))
Copy link
Member

Choose a reason for hiding this comment

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

And here we prefer: assertThatExceptionOfType(MessageDeliveryException.class).isThrownBy().

QueueChannel channel = new QueueChannel();
channel.addInterceptor(interceptor);
channel.send(new GenericMessage<>("test1"));
assertThatThrownBy(() -> channel.send(new GenericMessage<>("test1")))
Copy link
Member

Choose a reason for hiding this comment

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

Same here

assertThat(outputChannel.receive(0)).isNull();
}

}).isInstanceOf(MessageRejectedException.class);
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit awkward situation.
I guess it is hard to get rid of finally block, so let's see if extracting exception into a variable from that catch block, and then assert it in the end would make the test easier to digest!

assertThat(message).isEqualTo(e.getFailedMessage());
throw e;
}
}).isInstanceOf(MessagingException.class);
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 AssertJ API to extract object properties smooth way without this composition which maybe lost.
Something like:

		assertThatExceptionOfType(MessagingException.class)
				.isThrownBy(() -> handler.handleMessage(message))
				.extracting(MessagingException::getFailedMessage)
				.isEqualTo(message);

@Test
public void testDefaultConfigNoLocationPattern() {
new ClassPathXmlApplicationContext("ResourcePatternResolver-config-fail.xml", getClass()).close();
assertThatThrownBy(() -> new ClassPathXmlApplicationContext("ResourcePatternResolver-config-fail.xml", getClass()).close())
Copy link
Member

Choose a reason for hiding this comment

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

I think with this AssertJ API we don't need that close() any more.
Previously it was a code quality question to have Closable resource closed.
The fact that it ended up with an exception was not visible for that tool.

assertThat(result1a).isNotNull();
assertThat(result1a.getPayload()).isEqualTo("blocker");
assertThat(channelB.receive(0)).isNull();
assertThat(channelC.receive(0)).isNull();
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't look like this logic has to be done inside catch block.
We simply can move all of these assertions after assertThatExceptionOfTyle().
This way the code in this test would be much easier to read.

router.setChannels(null);
assertThatThrownBy(() -> {
router.setChannels(null);
}).isInstanceOf(IllegalArgumentException.class);
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't look like we need body for the lambda. I mean {} and ; in the end of sentence are redundant.

@mjd507
Copy link
Contributor Author

mjd507 commented May 6, 2025

hi @artembilan

I read the comments again, and found the they're really new and useful for me.

So leave this PR open, I will address the pr comments this evening, probably your tomorrow morning time.

Not fully automated, I utilize the open-rewrite tool(see config) but only applies its simplest recipe, which is change the @test to Jupiter package, then I change all changed files manually, really huge😉

Signed-off-by: Jiandong Ma <[email protected]>
@mjd507 mjd507 requested a review from artembilan May 7, 2025 13:04
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.

Will apply my suggestion on merge.
Thanks

@artembilan artembilan added this to the 6.5.0 milestone May 7, 2025
@artembilan artembilan merged commit 587693f into spring-projects:main May 7, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants