Skip to content

Commit 06679a5

Browse files
committed
Fix tests in DispatcherServletTests
See gh-28424
1 parent 745eb1a commit 06679a5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

spring-webmvc/src/test/java/org/springframework/web/servlet/DispatcherServletTests.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import javax.servlet.http.HttpServletRequestWrapper;
3131
import javax.servlet.http.HttpServletResponse;
3232

33+
import org.assertj.core.api.InstanceOfAssertFactories;
3334
import org.junit.jupiter.api.BeforeEach;
3435
import org.junit.jupiter.api.Test;
3536

@@ -519,7 +520,10 @@ public void detectAllHandlerAdapters() throws ServletException, IOException {
519520

520521
request = new MockHttpServletRequest(getServletContext(), "GET", "/form.do");
521522
response = new MockHttpServletResponse();
523+
request.addParameter("fail", "yes");
522524
complexDispatcherServlet.service(request, response);
525+
assertThat(response.getForwardedUrl()).as("forwarded URL").isEqualTo("failed1.jsp");
526+
assertThat(request.getAttribute("exception")).isNull();
523527
}
524528

525529
@Test
@@ -536,12 +540,15 @@ public void notDetectAllHandlerAdapters() throws ServletException, IOException {
536540
complexDispatcherServlet.service(request, response);
537541
assertThat(response.getContentAsString()).isEqualTo("body");
538542

539-
// SimpleControllerHandlerAdapter not detected
543+
// MyHandlerAdapter not detected
540544
request = new MockHttpServletRequest(getServletContext(), "GET", "/form.do");
541545
response = new MockHttpServletResponse();
546+
request.addParameter("fail", "yes");
542547
complexDispatcherServlet.service(request, response);
543-
assertThat(response.getForwardedUrl()).as("forwarded to failed").isEqualTo("failed0.jsp");
544-
assertThat(request.getAttribute("exception").getClass().equals(ServletException.class)).as("Exception exposed").isTrue();
548+
assertThat(response.getForwardedUrl()).as("forwarded URL").isEqualTo("failed0.jsp");
549+
assertThat(request.getAttribute("exception"))
550+
.asInstanceOf(InstanceOfAssertFactories.type(ServletException.class))
551+
.extracting(Throwable::getMessage).asString().startsWith("No adapter for handler");
545552
}
546553

547554
@Test

0 commit comments

Comments
 (0)