StaticFileServer implements StaticFileHandler { protected boolean browserHasNewestVersion(HttpServletRequest request, long resourceLastModifiedTimestamp) { assert resourceLastModifiedTimestamp >= -1L; if (resourceLastModifiedTimestamp == -1L) { return false; } try { long headerIfModifiedSince = request .getDateHeader("If-Modified-Since"); if (headerIfModifiedSince >= resourceLastModifiedTimestamp) { return true; } } catch (Exception e) { getLogger().trace("Unable to parse If-Modified-Since", e); } return false; } StaticFileServer(VaadinServletService servletService); @Override boolean isStaticResourceRequest(HttpServletRequest request); @Override boolean serveStaticResource(HttpServletRequest request,
            HttpServletResponse response);  }
@Test public void browserHasNewestVersionUnknownModificiationTime() { Assert.assertFalse(fileServer.browserHasNewestVersion(request, -1)); }
@Test(expected = AssertionError.class) public void browserHasNewestVersionInvalidModificiationTime() { fileServer.browserHasNewestVersion(request, -2); }
@Test public void browserHasNewestVersionNoIfModifiedSinceHeader() { long fileModifiedTime = 0; Assert.assertFalse( fileServer.browserHasNewestVersion(request, fileModifiedTime)); }
@Test public void browserHasNewestVersionOlderIfModifiedSinceHeader() { long browserIfModifiedSince = 123L; long fileModifiedTime = 124L; Mockito.when(request.getDateHeader("If-Modified-Since")) .thenReturn(browserIfModifiedSince); Assert.assertFalse( fileServer.browserHasNewestVersion(request, fileModifiedTime)); }
@Test public void browserHasNewestVersionNewerIfModifiedSinceHeader() { long browserIfModifiedSince = 125L; long fileModifiedTime = 124L; Mockito.when(request.getDateHeader("If-Modified-Since")) .thenReturn(browserIfModifiedSince); Assert.assertTrue( fileServer.browserHasNewestVersion(request, fileModifiedTime)); }