Skip to content

Commit 17e4c24

Browse files
committed
Avoid use of deprecated AssertJ APIs
1 parent 43a60a7 commit 17e4c24

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
package org.springframework.web.servlet.mvc.condition;
1818

1919
import jakarta.servlet.http.HttpServletRequest;
20-
import org.assertj.core.api.StringAssert;
2120
import org.junit.jupiter.api.Test;
2221

2322
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
2423
import org.springframework.web.util.ServletRequestPathUtils;
2524
import org.springframework.web.util.pattern.PathPatternParser;
2625

2726
import static org.assertj.core.api.Assertions.assertThat;
27+
import static org.assertj.core.api.InstanceOfAssertFactories.STRING;
2828

2929
/**
3030
* Tests for {@link PathPatternsRequestCondition}.
@@ -43,7 +43,7 @@ void prependSlash() {
4343

4444
@Test
4545
void prependNonEmptyPatternsOnly() {
46-
assertThat(createCondition("").getPatternValues(), StringAssert.class).element(0)
46+
assertThat(createCondition("").getPatternValues()).first(STRING)
4747
.as("Do not prepend empty patterns (SPR-8255)").isEmpty();
4848
}
4949

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
import java.util.Collections;
2020

2121
import jakarta.servlet.http.HttpServletRequest;
22-
import org.assertj.core.api.StringAssert;
2322
import org.junit.jupiter.api.Test;
2423

2524
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
2625
import org.springframework.web.util.UrlPathHelper;
2726

2827
import static org.assertj.core.api.Assertions.assertThat;
28+
import static org.assertj.core.api.InstanceOfAssertFactories.STRING;
2929

3030
/**
3131
* Tests for {@link PatternsRequestCondition}.
@@ -41,7 +41,7 @@ void prependSlash() {
4141

4242
@Test
4343
void prependNonEmptyPatternsOnly() {
44-
assertThat(new PatternsRequestCondition("").getPatterns(), StringAssert.class).element(0)
44+
assertThat(new PatternsRequestCondition("").getPatterns()).first(STRING)
4545
.as("Do not prepend empty patterns (SPR-8255)").isEmpty();
4646
}
4747

@@ -183,7 +183,7 @@ void matchTrailingSlash() {
183183
match = condition.getMatchingCondition(request);
184184

185185
assertThat(match).isNotNull();
186-
assertThat(match.getPatterns(), StringAssert.class).element(0)
186+
assertThat(match.getPatterns()).first(STRING)
187187
.as("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)")
188188
.isEqualTo("/foo/");
189189

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ void modelAttribute() {
126126
HandlerMethod hm = handlerMethod(new ValidController(), c -> c.handle(mockPerson));
127127
this.request.addParameter("name", "name=Faustino1234");
128128

129-
MethodArgumentNotValidException ex = catchThrowableOfType(
130-
() -> this.handlerAdapter.handle(this.request, this.response, hm),
131-
MethodArgumentNotValidException.class);
129+
MethodArgumentNotValidException ex = catchThrowableOfType(MethodArgumentNotValidException.class,
130+
() -> this.handlerAdapter.handle(this.request, this.response, hm));
132131

133132
assertThat(this.jakartaValidator.getValidationCount()).isEqualTo(1);
134133
assertThat(this.jakartaValidator.getMethodValidationCount()).as("Method validation unexpected").isEqualTo(0);
@@ -167,9 +166,8 @@ void modelAttributeWithBindingResultAndRequestHeader() {
167166
this.request.addParameter("name", "name=Faustino1234");
168167
this.request.addHeader("myHeader", "123");
169168

170-
HandlerMethodValidationException ex = catchThrowableOfType(
171-
() -> this.handlerAdapter.handle(this.request, this.response, hm),
172-
HandlerMethodValidationException.class);
169+
HandlerMethodValidationException ex = catchThrowableOfType(HandlerMethodValidationException.class,
170+
() -> this.handlerAdapter.handle(this.request, this.response, hm));
173171

174172
assertThat(this.jakartaValidator.getValidationCount()).isEqualTo(1);
175173
assertThat(this.jakartaValidator.getMethodValidationCount()).isEqualTo(1);
@@ -223,9 +221,8 @@ void validateList() {
223221
this.request.setContentType(MediaType.APPLICATION_JSON_VALUE);
224222
this.request.setContent("[{\"name\":\"Faustino1234\"},{\"name\":\"Cayetana6789\"}]".getBytes(UTF_8));
225223

226-
HandlerMethodValidationException ex = catchThrowableOfType(
227-
() -> this.handlerAdapter.handle(this.request, this.response, hm),
228-
HandlerMethodValidationException.class);
224+
HandlerMethodValidationException ex = catchThrowableOfType(HandlerMethodValidationException.class,
225+
() -> this.handlerAdapter.handle(this.request, this.response, hm));
229226

230227
assertThat(this.jakartaValidator.getValidationCount()).isEqualTo(1);
231228
assertThat(this.jakartaValidator.getMethodValidationCount()).isEqualTo(1);

0 commit comments

Comments
 (0)