StaticFileServer implements StaticFileHandler { @Override public boolean isStaticResourceRequest(HttpServletRequest request) { URL resource; String requestFilename = getRequestFilename(request); if (requestFilename.endsWith("/")) { return false; } if (requestFilename.startsWith("/" + VAADIN_STATIC_FILES_PATH) || requestFilename.startsWith("/" + VAADIN_BUILD_FILES_PATH)) { return true; } resource = servletService.getStaticResource(requestFilename); if (resource == null && shouldFixIncorrectWebjarPaths() && isIncorrectWebjarPath(requestFilename)) { return true; } return resource != null; } StaticFileServer(VaadinServletService servletService); @Override boolean isStaticResourceRequest(HttpServletRequest request); @Override boolean serveStaticResource(HttpServletRequest request,
            HttpServletResponse response);  }
@Test public void isResourceRequest() throws Exception { setupRequestURI("", "/static", "/file.png"); Mockito.when(servletService.getStaticResource("/static/file.png")) .thenReturn(new URL("file: Assert.assertTrue(fileServer.isStaticResourceRequest(request)); }
@Test public void isResourceRequestWithContextPath() throws Exception { setupRequestURI("/foo", "/static", "/file.png"); Mockito.when(servletService.getStaticResource("/static/file.png")) .thenReturn(new URL("file: Assert.assertTrue(fileServer.isStaticResourceRequest(request)); }
@Test public void isNotResourceRequest() throws Exception { setupRequestURI("", "", null); Mockito.when(servletContext.getResource("/")).thenReturn(null); Assert.assertFalse(fileServer.isStaticResourceRequest(request)); }
@Test public void isNotResourceRequestWithContextPath() throws Exception { setupRequestURI("/context", "", "/"); Mockito.when(servletContext.getResource("/")).thenReturn(new URL("file", "", -1, "flow/flow-tests/non-root-context-test/src/main/webapp/", new URLStreamHandler() { @Override protected URLConnection openConnection(URL u) throws IOException { URLConnection mock = Mockito.mock(URLConnection.class); return mock; } })); Assert.assertFalse(fileServer.isStaticResourceRequest(request)); }