1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Migrate to assertThatExceptionOfType

Consistently use `assertThatExceptionOfType(...).isThrownBy(...)`
rather than `assertThatCode` or `assertThatThrownBy`. This aligns with
Spring Boot and Spring Cloud. It also allows the convenience
`assertThatIllegalArgument` and `assertThatIllegalState` methods to
be used.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-08-04 14:20:45 -07:00
committed by Rob Winch
parent ef8f113619
commit 319d3364aa
196 changed files with 2241 additions and 2116 deletions
@@ -32,6 +32,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.fail;
/**
@@ -138,15 +139,8 @@ public class ApacheDSContainerTests {
server.setLdapOverSslEnabled(true);
server.setKeyStoreFile(temporaryKeyStoreFile);
server.setCertificatePassord("incorrect-password");
try {
server.afterPropertiesSet();
fail("Expected a RuntimeException to be thrown.");
}
catch (RuntimeException ex) {
assertThat(ex).hasMessage("Server startup failed");
assertThat(ex).hasRootCauseInstanceOf(UnrecoverableKeyException.class);
}
assertThatExceptionOfType(RuntimeException.class).isThrownBy(server::afterPropertiesSet)
.withMessage("Server startup failed").withRootCauseInstanceOf(UnrecoverableKeyException.class);
}
/**
@@ -36,7 +36,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests for {@link LdapUserDetailsManager#changePassword}, specifically relating to the
@@ -63,8 +63,8 @@ public class LdapUserDetailsManagerModifyPasswordTests {
@Test
@WithMockUser(username = "bob", password = "bobspassword", authorities = "ROLE_USER")
public void changePasswordWhenOldPasswordIsIncorrectThenThrowsException() {
assertThatCode(() -> this.userDetailsManager.changePassword("wrongoldpassword", "bobsnewpassword"))
.isInstanceOf(BadCredentialsException.class);
assertThatExceptionOfType(BadCredentialsException.class)
.isThrownBy(() -> this.userDetailsManager.changePassword("wrongoldpassword", "bobsnewpassword"));
}
@Test