Browse Source

Avoid use of deprecated AssertJ APIs

pull/32966/head
Sam Brannen 2 years ago
parent
commit
17e4c241c3
  1. 4
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java
  2. 6
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java
  3. 15
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MethodValidationTests.java

4
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java

@ -17,7 +17,6 @@ @@ -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; @@ -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 { @@ -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();
}

6
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java

@ -19,13 +19,13 @@ package org.springframework.web.servlet.mvc.condition; @@ -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 { @@ -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 { @@ -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/");

15
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MethodValidationTests.java

@ -126,9 +126,8 @@ class MethodValidationTests { @@ -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 { @@ -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 { @@ -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);

Loading…
Cancel
Save