### Question:
Servlet3DispatcherTypeProvider implements DispatcherTypeProvider { @Override public DispatcherType getDispatcherType(ServletRequest request, ServletContext context) { if (context.getMajorVersion() >= 3) { return DispatcherType.valueOf(request.getDispatcherType().name()); } return null; }  @Override int priority(); @Override DispatcherType getDispatcherType(ServletRequest request, ServletContext context);  }### Answer:
@Test public void testShouldReturnCorrectDispatcherTypeForServlet3() { ServletContext servletContext = mock(ServletContext.class); when(servletContext.getMajorVersion()).thenReturn(3); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getDispatcherType()).thenReturn(javax.servlet.DispatcherType.FORWARD); DispatcherTypeProvider provider = new Servlet3DispatcherTypeProvider(); DispatcherType dispatcherType = provider.getDispatcherType(request, servletContext); assertEquals(DispatcherType.FORWARD, dispatcherType); }
@Test public void testShouldReturnNullForServlet25() { ServletContext servletContext = mock(ServletContext.class); when(servletContext.getMajorVersion()).thenReturn(2); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getDispatcherType()).thenThrow(new IllegalStateException("Call not allowed")); DispatcherTypeProvider provider = new Servlet3DispatcherTypeProvider(); DispatcherType dispatcherType = provider.getDispatcherType(request, servletContext); assertNull(dispatcherType); }