|
1 | 1 | package com.vaadin.flow.server.startup; |
2 | 2 |
|
3 | | -import static java.util.Collections.singletonList; |
4 | | -import static java.util.Collections.singletonMap; |
5 | | -import static org.junit.Assert.assertEquals; |
6 | | -import static org.junit.Assert.assertTrue; |
| 3 | +import jakarta.servlet.Registration; |
| 4 | +import jakarta.servlet.Servlet; |
| 5 | +import jakarta.servlet.ServletConfig; |
| 6 | +import jakarta.servlet.ServletContext; |
| 7 | +import jakarta.servlet.ServletContextEvent; |
| 8 | +import jakarta.servlet.ServletRegistration; |
| 9 | +import jakarta.servlet.ServletRequest; |
| 10 | +import jakarta.servlet.ServletResponse; |
7 | 11 |
|
8 | 12 | import java.io.File; |
9 | 13 | import java.nio.charset.StandardCharsets; |
|
17 | 21 | import java.util.stream.Collectors; |
18 | 22 | import java.util.stream.Stream; |
19 | 23 |
|
20 | | -import jakarta.servlet.Registration; |
21 | | -import jakarta.servlet.Servlet; |
22 | | -import jakarta.servlet.ServletConfig; |
23 | | -import jakarta.servlet.ServletContext; |
24 | | -import jakarta.servlet.ServletContextEvent; |
25 | | -import jakarta.servlet.ServletRegistration; |
26 | | -import jakarta.servlet.ServletRequest; |
27 | | -import jakarta.servlet.ServletResponse; |
| 24 | +import org.apache.commons.io.FileUtils; |
| 25 | +import org.junit.Before; |
| 26 | +import org.junit.Rule; |
| 27 | +import org.junit.Test; |
| 28 | +import org.junit.rules.TemporaryFolder; |
| 29 | +import org.mockito.ArgumentMatchers; |
| 30 | +import org.mockito.Mockito; |
28 | 31 |
|
29 | 32 | import com.vaadin.flow.component.Component; |
30 | 33 | import com.vaadin.flow.di.Lookup; |
|
33 | 36 | import com.vaadin.flow.server.InitParameters; |
34 | 37 | import com.vaadin.flow.server.frontend.FrontendUtils; |
35 | 38 |
|
36 | | -import org.apache.commons.io.FileUtils; |
37 | | -import org.junit.Before; |
38 | | -import org.junit.Rule; |
39 | | -import org.junit.Test; |
40 | | -import org.junit.rules.TemporaryFolder; |
41 | | -import org.mockito.ArgumentMatchers; |
42 | | -import org.mockito.Mockito; |
| 39 | +import static java.util.Collections.singletonList; |
| 40 | +import static java.util.Collections.singletonMap; |
| 41 | +import static org.junit.Assert.assertEquals; |
| 42 | +import static org.junit.Assert.assertTrue; |
43 | 43 |
|
44 | 44 | public class ServletDeployerTest { |
45 | 45 | private final ServletDeployer deployer = new ServletDeployer(); |
@@ -143,6 +143,18 @@ public void frontendServletIsNotRegistered_whenMainServletIsRegistered() |
143 | 143 | assertLoadOnStartupSet(); |
144 | 144 | } |
145 | 145 |
|
| 146 | + @Test |
| 147 | + public void servletsWithoutClassName_registrationDoesNotFail() |
| 148 | + throws Exception { |
| 149 | + deployer.contextInitialized(getContextEvent(getServletRegistration( |
| 150 | + "test", null, singletonList("/WEB-INF/test.jsp"), |
| 151 | + Collections.emptyMap()))); |
| 152 | + |
| 153 | + assertMappingsCount(1, 1); |
| 154 | + assertMappingIsRegistered(ServletDeployer.class.getName(), "/*"); |
| 155 | + assertLoadOnStartupSet(); |
| 156 | + } |
| 157 | + |
146 | 158 | @Test |
147 | 159 | public void servletIsNotRegisteredWhenAnotherHasTheSamePathMapping_mainServlet() |
148 | 160 | throws Exception { |
@@ -281,8 +293,8 @@ private ServletRegistration getServletRegistration(String servletName, |
281 | 293 | Map<String, String> initParameters) { |
282 | 294 | ServletRegistration registrationMock = Mockito |
283 | 295 | .mock(ServletRegistration.class); |
284 | | - Mockito.when(registrationMock.getClassName()) |
285 | | - .thenReturn(servletClass.getName()); |
| 296 | + Mockito.when(registrationMock.getClassName()).thenReturn( |
| 297 | + servletClass != null ? servletClass.getName() : null); |
286 | 298 | Mockito.when(registrationMock.getMappings()).thenReturn(pathMappings); |
287 | 299 | Mockito.when(registrationMock.getName()).thenReturn(servletName); |
288 | 300 | Mockito.when(registrationMock.getInitParameters()) |
|
0 commit comments