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:
+3
-9
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user