Skip to content

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

assertThat(validated.value()).containsExactly(BeanGroup.class);
});
}
Expand All @@ -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();
Copy link
Member

Choose a reason for hiding this comment

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

As above. Please revert.

assertThat(validated.value()).containsExactly(FactoryMethodGroup.class);
});
}
Expand All @@ -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();
Copy link
Member

Choose a reason for hiding this comment

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

As above. Please revert.

assertThat(validated.value()).containsExactly(FactoryMethodGroup.class);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ConfigurationPropertiesBean.get() is @Nullable

Copy link
Member

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.

ConfigurationPropertiesBindException exception = new ConfigurationPropertiesBindException(bean,
new IllegalStateException());
assertThat(exception.getMessage()).isEqualTo("Error creating bean with name 'example': "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

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

As above. Please revert.

Set<ConfigurationPropertyName> keys = bound.getAll().keySet();
assertThat(keys.stream().map(ConfigurationPropertyName::toString)).contains("name", "nested.name");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import java.util.function.Supplier;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.fail;

/**
* Tests for {@link PropertyMapper}.
Expand Down Expand Up @@ -57,7 +57,7 @@ void fromValueAsIntShouldAdaptValue() {

@Test
void fromValueAlwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(() -> fail());
this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(Assertions::fail);
}

@Test
Expand Down Expand Up @@ -101,14 +101,14 @@ void asShouldAdaptSupplier() {

@Test
void whenNonNullWhenSuppliedNullShouldNotMap() {
this.map.from(() -> null).whenNonNull().as(String::valueOf).toCall(() -> fail());
this.map.from(() -> null).whenNonNull().as(String::valueOf).toCall(Assertions::fail);
}

@Test
void whenNonNullWhenSuppliedThrowsNullPointerExceptionShouldNotMap() {
this.map.from(() -> {
throw new NullPointerException();
}).whenNonNull().as(String::valueOf).toCall(() -> fail());
}).whenNonNull().as(String::valueOf).toCall(Assertions::fail);
}

@Test
Expand All @@ -119,7 +119,7 @@ void whenTrueWhenValueIsTrueShouldMap() {

@Test
void whenTrueWhenValueIsFalseShouldNotMap() {
this.map.from(false).whenTrue().toCall(() -> fail());
this.map.from(false).whenTrue().toCall(Assertions::fail);
}

@Test
Expand All @@ -130,17 +130,17 @@ void whenFalseWhenValueIsFalseShouldMap() {

@Test
void whenFalseWhenValueIsTrueShouldNotMap() {
this.map.from(true).whenFalse().toCall(() -> fail());
this.map.from(true).whenFalse().toCall(Assertions::fail);
}

@Test
void whenHasTextWhenValueIsNullShouldNotMap() {
this.map.from(() -> null).whenHasText().toCall(() -> fail());
this.map.from(() -> null).whenHasText().toCall(Assertions::fail);
}

@Test
void whenHasTextWhenValueIsEmptyShouldNotMap() {
this.map.from("").whenHasText().toCall(() -> fail());
this.map.from("").whenHasText().toCall(Assertions::fail);
}

@Test
Expand All @@ -157,7 +157,7 @@ void whenEqualToWhenValueIsEqualShouldMatch() {

@Test
void whenEqualToWhenValueIsNotEqualShouldNotMatch() {
this.map.from("123").whenEqualTo("321").toCall(() -> fail());
this.map.from("123").whenEqualTo("321").toCall(Assertions::fail);
}

@Test
Expand All @@ -169,7 +169,7 @@ void whenInstanceOfWhenValueIsTargetTypeShouldMatch() {
@Test
void whenInstanceOfWhenValueIsNotTargetTypeShouldNotMatch() {
Supplier<Number> supplier = () -> 123L;
this.map.from(supplier).whenInstanceOf(Double.class).toCall(() -> fail());
this.map.from(supplier).whenInstanceOf(Double.class).toCall(Assertions::fail);
}

@Test
Expand All @@ -180,7 +180,7 @@ void whenWhenValueMatchesShouldMap() {

@Test
void whenWhenValueDoesNotMatchShouldNotMap() {
this.map.from("123").when("321"::equals).toCall(() -> fail());
this.map.from("123").when("321"::equals).toCall(Assertions::fail);
}

@Test
Expand All @@ -198,12 +198,12 @@ void whenWhenCombinedWithAsUsesSourceValue() {

@Test
void alwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
this.map.alwaysApplyingWhenNonNull().from(() -> null).toCall(() -> fail());
this.map.alwaysApplyingWhenNonNull().from(() -> null).toCall(Assertions::fail);
}

@Test
void whenWhenValueNotMatchesShouldSupportChainedCalls() {
this.map.from("123").when("456"::equals).when("123"::equals).toCall(() -> fail());
this.map.from("123").when("456"::equals).when("123"::equals).toCall(Assertions::fail);
}

@Test
Expand Down