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
@@ -44,7 +44,7 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
@@ -76,8 +76,9 @@ public class SecurityMockServerConfigurersOAuth2ClientTests extends AbstractMock
@Test
public void oauth2ClientWhenUsingDefaultsThenException() throws Exception {
WebHttpHandlerBuilder builder = WebHttpHandlerBuilder.webHandler(new DispatcherHandler());
assertThatCode(() -> SecurityMockServerConfigurers.mockOAuth2Client().beforeServerCreated(builder))
.isInstanceOf(IllegalArgumentException.class).hasMessageContaining("ClientRegistration");
assertThatIllegalArgumentException()
.isThrownBy(() -> SecurityMockServerConfigurers.mockOAuth2Client().beforeServerCreated(builder))
.withMessageContaining("ClientRegistration");
}
@Test
@@ -49,7 +49,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
@@ -93,8 +93,9 @@ public class SecurityMockMvcRequestPostProcessorsOAuth2ClientTests {
@Test
public void oauth2ClientWhenUsingDefaultsThenException() throws Exception {
assertThatCode(() -> oauth2Client().postProcessRequest(new MockHttpServletRequest()))
.isInstanceOf(IllegalArgumentException.class).hasMessageContaining("ClientRegistration");
assertThatIllegalArgumentException()
.isThrownBy(() -> oauth2Client().postProcessRequest(new MockHttpServletRequest()))
.withMessageContaining("ClientRegistration");
}
@Test