### Question:
Servlet3ServletRegistrationProvider implements ServletRegistrationProvider { @Override public List<ServletRegistration> getServletRegistrations(ServletContext context) { if (context.getMajorVersion() >= 3) { List<ServletRegistration> result = new ArrayList<ServletRegistration>(); for (javax.servlet.ServletRegistration r : context.getServletRegistrations().values()) { ServletRegistration registration = new ServletRegistration(); registration.setClassName(r.getClassName()); registration.addMappings(r.getMappings()); result.add(registration); } return result; } return null; }  @Override int priority(); @Override List<ServletRegistration> getServletRegistrations(ServletContext context);  }### Answer:
@Test public void testShouldReturnNullForOldServletVersions() { ServletContext servletContext = mock(ServletContext.class); when(servletContext.getMajorVersion()).thenReturn(2); Servlet3ServletRegistrationProvider provider = new Servlet3ServletRegistrationProvider(); List<ServletRegistration> registrations = provider.getServletRegistrations(servletContext); assertNull(registrations); }
@Test public void testShouldReturnEmptyListForNoRegistrations() { ServletContext servletContext = mock(ServletContext.class); when(servletContext.getMajorVersion()).thenReturn(3); when(servletContext.getServletRegistrations()).thenReturn(new HashMap()); Servlet3ServletRegistrationProvider provider = new Servlet3ServletRegistrationProvider(); List<ServletRegistration> result = provider.getServletRegistrations(servletContext); assertNotNull(result); assertEquals(0, result.size()); }
@Test public void testShouldReturnCorrectRegistrationWithExistingRegistrations() { ServletContext servletContext = mock(ServletContext.class); when(servletContext.getMajorVersion()).thenReturn(3); javax.servlet.ServletRegistration registration = mock(javax.servlet.ServletRegistration.class); when(registration.getClassName()).thenReturn("com.example.MyServlet"); when(registration.getMappings()).thenReturn(Arrays.asList("*.jsf", "/faces/*")); Map registrationMap = new HashMap(); registrationMap.put("test", registration); when(servletContext.getServletRegistrations()).thenReturn(registrationMap); Servlet3ServletRegistrationProvider provider = new Servlet3ServletRegistrationProvider(); List<ServletRegistration> result = provider.getServletRegistrations(servletContext); assertNotNull(result); assertEquals(1, result.size()); assertEquals("com.example.MyServlet", result.get(0).getClassName()); assertEquals(Arrays.asList("*.jsf", "/faces/*"), result.get(0).getMappings()); }