-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Polish tests #42725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polish tests #42725
Conversation
quaff
commented
Oct 17, 2024
- Improve null safety
- Replace lambda with method reference
1. Improve null safety 2. Replace lambda with method reference
@@ -197,6 +197,7 @@ void getWhenHasFactoryMethodAndBeanAnnotationFavorsFactoryMethod() throws Throwa | |||
void getWhenHasValidatedBeanBindsWithBeanAnnotation() throws Throwable { | |||
get(ValidatedBeanConfiguration.class, "validatedBean", (propertiesBean) -> { | |||
Validated validated = propertiesBean.asBindTarget().getAnnotation(Validated.class); | |||
assertThat(validated).isNotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is an improvement. It makes the test more verbose and I think the benefit is negligible. Should validated
be null
, the NPE that would occur on the next line when calling validated.value()
will make that clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes IDEA and code analysis tools happy, is it worthy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think so.
@@ -205,6 +206,7 @@ void getWhenHasValidatedBeanBindsWithBeanAnnotation() throws Throwable { | |||
void getWhenHasValidatedFactoryMethodBindsWithFactoryMethodAnnotation() throws Throwable { | |||
get(ValidatedMethodConfiguration.class, "annotatedBean", (propertiesBean) -> { | |||
Validated validated = propertiesBean.asBindTarget().getAnnotation(Validated.class); | |||
assertThat(validated).isNotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above. Please revert.
@@ -213,6 +215,7 @@ void getWhenHasValidatedFactoryMethodBindsWithFactoryMethodAnnotation() throws T | |||
void getWhenHasValidatedBeanAndFactoryMethodBindsWithFactoryMethodAnnotation() throws Throwable { | |||
get(ValidatedMethodAndBeanConfiguration.class, "validatedBean", (propertiesBean) -> { | |||
Validated validated = propertiesBean.asBindTarget().getAnnotation(Validated.class); | |||
assertThat(validated).isNotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above. Please revert.
@@ -36,6 +36,7 @@ void createFromBeanHasDetails() { | |||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Example.class); | |||
ConfigurationPropertiesBean bean = ConfigurationPropertiesBean.get(applicationContext, | |||
applicationContext.getBean(Example.class), "example"); | |||
assertThat(bean).isNotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above. Please revert. Additionally, getBean(Class)
will never return null
, throwing a NoSuchBeanDefinitionException
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConfigurationPropertiesBean.get()
is @Nullable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I misread the diff. Regardless, the same reasoning as above still applies. I don't think null checks such as this in tests are beneficial.
@@ -1197,6 +1197,7 @@ void loadWhenBoundToRandomPropertyPlaceholder() { | |||
void boundPropertiesShouldBeRecorded() { | |||
load(NestedConfiguration.class, "name=foo", "nested.name=bar"); | |||
BoundConfigurationProperties bound = BoundConfigurationProperties.get(this.context); | |||
assertThat(bound).isNotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above. Please revert.
Replace lambdas with method references See gh-42725