Avoid use of deprecated AssertJ APIs

This commit is contained in:
Sam Brannen 2024-06-05 14:50:30 +02:00
parent 43a60a7e3f
commit 17e4c241c3
3 changed files with 11 additions and 14 deletions

View File

@ -17,7 +17,6 @@
package org.springframework.web.servlet.mvc.condition;
import jakarta.servlet.http.HttpServletRequest;
import org.assertj.core.api.StringAssert;
import org.junit.jupiter.api.Test;
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
@ -25,6 +24,7 @@ import org.springframework.web.util.ServletRequestPathUtils;
import org.springframework.web.util.pattern.PathPatternParser;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.STRING;
/**
* Tests for {@link PathPatternsRequestCondition}.
@ -43,7 +43,7 @@ class PathPatternsRequestConditionTests {
@Test
void prependNonEmptyPatternsOnly() {
assertThat(createCondition("").getPatternValues(), StringAssert.class).element(0)
assertThat(createCondition("").getPatternValues()).first(STRING)
.as("Do not prepend empty patterns (SPR-8255)").isEmpty();
}

View File

@ -19,13 +19,13 @@ package org.springframework.web.servlet.mvc.condition;
import java.util.Collections;
import jakarta.servlet.http.HttpServletRequest;
import org.assertj.core.api.StringAssert;
import org.junit.jupiter.api.Test;
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
import org.springframework.web.util.UrlPathHelper;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.STRING;
/**
* Tests for {@link PatternsRequestCondition}.
@ -41,7 +41,7 @@ class PatternsRequestConditionTests {
@Test
void prependNonEmptyPatternsOnly() {
assertThat(new PatternsRequestCondition("").getPatterns(), StringAssert.class).element(0)
assertThat(new PatternsRequestCondition("").getPatterns()).first(STRING)
.as("Do not prepend empty patterns (SPR-8255)").isEmpty();
}
@ -183,7 +183,7 @@ class PatternsRequestConditionTests {
match = condition.getMatchingCondition(request);
assertThat(match).isNotNull();
assertThat(match.getPatterns(), StringAssert.class).element(0)
assertThat(match.getPatterns()).first(STRING)
.as("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)")
.isEqualTo("/foo/");

View File

@ -126,9 +126,8 @@ class MethodValidationTests {
HandlerMethod hm = handlerMethod(new ValidController(), c -> c.handle(mockPerson));
this.request.addParameter("name", "name=Faustino1234");
MethodArgumentNotValidException ex = catchThrowableOfType(
() -> this.handlerAdapter.handle(this.request, this.response, hm),
MethodArgumentNotValidException.class);
MethodArgumentNotValidException ex = catchThrowableOfType(MethodArgumentNotValidException.class,
() -> this.handlerAdapter.handle(this.request, this.response, hm));
assertThat(this.jakartaValidator.getValidationCount()).isEqualTo(1);
assertThat(this.jakartaValidator.getMethodValidationCount()).as("Method validation unexpected").isEqualTo(0);
@ -167,9 +166,8 @@ class MethodValidationTests {
this.request.addParameter("name", "name=Faustino1234");
this.request.addHeader("myHeader", "123");
HandlerMethodValidationException ex = catchThrowableOfType(
() -> this.handlerAdapter.handle(this.request, this.response, hm),
HandlerMethodValidationException.class);
HandlerMethodValidationException ex = catchThrowableOfType(HandlerMethodValidationException.class,
() -> this.handlerAdapter.handle(this.request, this.response, hm));
assertThat(this.jakartaValidator.getValidationCount()).isEqualTo(1);
assertThat(this.jakartaValidator.getMethodValidationCount()).isEqualTo(1);
@ -223,9 +221,8 @@ class MethodValidationTests {
this.request.setContentType(MediaType.APPLICATION_JSON_VALUE);
this.request.setContent("[{\"name\":\"Faustino1234\"},{\"name\":\"Cayetana6789\"}]".getBytes(UTF_8));
HandlerMethodValidationException ex = catchThrowableOfType(
() -> this.handlerAdapter.handle(this.request, this.response, hm),
HandlerMethodValidationException.class);
HandlerMethodValidationException ex = catchThrowableOfType(HandlerMethodValidationException.class,
() -> this.handlerAdapter.handle(this.request, this.response, hm));
assertThat(this.jakartaValidator.getValidationCount()).isEqualTo(1);
assertThat(this.jakartaValidator.getMethodValidationCount()).isEqualTo(1);