Fix assertions whose result was ignored

Several tests called AssertJ's assertThat without chaining an assertion,
or chained withFailMessage after the assertion had already run, so they
verified nothing. Found with OpenRewrite's FindIgnoredCheckReturnValue.

See gh-52045

Signed-off-by: Tim te Beek <tim@moderne.io>
This commit is contained in:
Tim te Beek
2026-10-07 16:47:12 +02:00
committed by Stéphane Nicoll
parent 8a76a2dfef
commit a5e6f1bf7b
7 changed files with 14 additions and 13 deletions
@@ -409,8 +409,10 @@ class InitCommandTests extends AbstractHttpClientMockTests {
void userAgent() throws Exception {
this.command.run("--list", "--target=https://fake-service");
then(this.http).should()
.executeOpen(any(HttpHost.class), assertArg((request) -> assertThat(
request.getHeaders("User-Agent")[0].getValue().startsWith("SpringBootCli/"))), isNull());
.executeOpen(any(HttpHost.class),
assertArg((request) -> assertThat(request.getHeaders("User-Agent")[0].getValue())
.startsWith("SpringBootCli/")),
isNull());
}
private void withUserDir(File userDir, ThrowingRunnable action) throws Exception {
@@ -102,7 +102,7 @@ class JmxAutoConfigurationTests {
try (AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext()) {
parent.register(JmxAutoConfiguration.class);
parent.refresh();
this.contextRunner.withParent(parent).run((context) -> assertThat(context.isRunning()));
this.contextRunner.withParent(parent).run((context) -> assertThat(context.isRunning()).isTrue());
}
}
@@ -113,7 +113,7 @@ class JmxAutoConfigurationTests {
parent.refresh();
this.contextRunner.withParent(parent)
.withConfiguration(UserConfigurations.of(TestConfiguration.class))
.run((context) -> assertThat(context.isRunning()));
.run((context) -> assertThat(context.isRunning()).isTrue());
}
}
@@ -52,7 +52,7 @@ class Zip64EndOfCentralDirectoryRecordTests {
assertThat(eocd.numberOfCentralDirectoryEntriesOnThisDisk()).isEqualTo(6);
assertThat(eocd.totalNumberOfCentralDirectoryEntries()).isEqualTo(7);
assertThat(eocd.sizeOfCentralDirectory()).isEqualTo(8);
assertThat(eocd.offsetToStartOfCentralDirectory());
assertThat(eocd.offsetToStartOfCentralDirectory()).isEqualTo(9);
}
@Test
@@ -203,8 +203,8 @@ class ElasticsearchRestClientAutoConfigurationTests {
Rest5Client client = context.getBean(Rest5Client.class);
assertThat(client).extracting("defaultHeaders", InstanceOfAssertFactories.list(Header.class))
.satisfiesOnlyOnce((header) -> {
assertThat(header.getName().equals("Authorization"));
assertThat(header.getValue().equals("ApiKey some-api-key"));
assertThat(header.getName()).isEqualTo("Authorization");
assertThat(header.getValue()).isEqualTo("ApiKey some-api-key");
});
});
}
@@ -218,8 +218,8 @@ class ElasticsearchRestClientAutoConfigurationTests {
Rest5Client client = context.getBean(Rest5Client.class);
assertThat(client).extracting("defaultHeaders", InstanceOfAssertFactories.list(Header.class))
.satisfiesOnlyOnce((header) -> {
assertThat(header.getName().equals("Authorization"));
assertThat(header.getValue().equals("ApiKey some-api-key"));
assertThat(header.getName()).isEqualTo("Authorization");
assertThat(header.getValue()).isEqualTo("ApiKey some-api-key");
});
assertThat(client)
.extracting("client.credentialsProvider", InstanceOfAssertFactories.type(CredentialsProvider.class))
@@ -174,7 +174,7 @@ class RSocketServerAutoConfigurationTests {
.run((context) -> {
assertThat(context).hasFailed();
assertThat(context.getStartupFailure()).hasRootCauseInstanceOf(NoSuchSslBundleException.class)
.withFailMessage("SSL bundle name 'test-bundle' is not valid");
.hasRootCauseMessage("SSL bundle name 'test-bundle' cannot be found");
});
}
@@ -336,8 +336,7 @@ class Saml2RelyingPartyAutoConfigurationTests {
void causesManagementWebSecurityAutoConfigurationToBackOff() {
WebApplicationContextRunner contextRunner = this.contextRunner.withConfiguration(
AutoConfigurations.of(ManagementWebSecurityAutoConfiguration.class, WebMvcAutoConfiguration.class));
assertThat(contextRunner
.run((context) -> assertThat(context).hasSingleBean(ManagementWebSecurityAutoConfiguration.class)));
contextRunner.run((context) -> assertThat(context).hasSingleBean(ManagementWebSecurityAutoConfiguration.class));
contextRunner.withPropertyValues(PREFIX
+ ".simplesamlphp.assertingparty.single-sign-on.url=https://simplesaml-for-spring-saml/SSOService.php",
PREFIX + ".simplesamlphp.assertingparty.single-sign-on.sign-request=false",
@@ -108,7 +108,7 @@ public abstract class AbstractReactiveWebServerAutoConfigurationTests {
.run((context) -> {
assertThat(context).hasFailed();
assertThat(context.getStartupFailure().getCause()).isInstanceOf(NoSuchSslBundleException.class)
.withFailMessage("test");
.hasMessage("SSL bundle name 'test-bundle' cannot be found");
});
}