UnsupportedBrowserHandler extends SynchronizedRequestHandler { @Override public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { WebBrowser browser = session.getBrowser(); final String cookie = request.getHeader("Cookie"); if (browser.isTooOldToFunctionProperly()) { if (cookie == null || !cookie.contains(FORCE_LOAD_COOKIE)) { writeBrowserTooOldPage(request, response); return true; } } return false; }  @Override boolean synchronizedHandleRequest(VaadinSession session,
            VaadinRequest request, VaadinResponse response); static final String FORCE_LOAD_COOKIE; static final String CLOSING_BRACKET; }
@Test public void testUnsupportedBrowserHandler_validBrowser_doesntHandleRequest() throws IOException { initMocks(false, false); Assert.assertFalse("Should not handle the request", handler.synchronizedHandleRequest(session, request, response)); Mockito.verify(writer, Mockito.never()).write(Mockito.anyString()); }
@Test public void testUnsupportedBrowserHandler_tooOldBrowser_returnsUnsupportedBrowserPage() throws IOException { initMocks(false, true); Assert.assertTrue("Request should have been handled", handler.synchronizedHandleRequest(session, request, response)); Mockito.verify(writer).write(pageCapture.capture()); Assert.assertTrue("Unsupported browser page not used", pageCapture.getValue().contains( "I'm sorry, but your browser is not supported")); Mockito.verify(response).setContentType( ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8); }
@Test public void testUnsupportedBrowserHandler_tooOldBrowserWithForceReloadCookie_doesntHandleRequest() throws IOException { initMocks(true, true); Assert.assertFalse("Should not handle the request", handler.synchronizedHandleRequest(session, request, response)); Mockito.verify(writer, Mockito.never()).write(Mockito.anyString()); }
@Test public void testUnsupportedBrowserHandler_validBrowserWithForceReloadCookie_doesntHandleRequest() throws IOException { initMocks(true, false); Assert.assertFalse("Should not handle the request", handler.synchronizedHandleRequest(session, request, response)); Mockito.verify(writer, Mockito.never()).write(Mockito.anyString()); }