ServletContextHelper { public ServletMapping getResolvedServletMapping(final ServletContext servletContext, final String path) { Objects.requireNonNull(servletContext); for (ServletMapping servletMapping : servletContext.getServletMappings()) { String inContextPath = getPathInContext(servletContext, path); if (servletMapping.getUrlPattern().matcher(inContextPath).matches()) { return servletMapping; } } return null; }  ServletMapping getResolvedServletMapping(final ServletContext servletContext, final String path); ServletContextImpl getResolvedContext(final List<ServletContextImpl> servletContexts, final String path); List<FilterMapping> getFilterMappingsForPath(final ServletContext servletContext, final String path);  }
@Test public void shouldNotResolveFirstServletMappingWhenEmptyContextMapping() { assertThat(servletContextHelper.getResolvedServletMapping(servletContext, "/context/somepath"), is(nullValue())); }
@Test public void shouldNotResolveFirstServletMappingWhenNoMatchingElements() { ServletMapping servletMapping1 = new ServletMappingImpl(Pattern.compile("^/notmatching.*$"), SampleServlet.class); when(servletContext.getServletMappings()).thenReturn(Arrays.asList(servletMapping1)); assertThat(servletContextHelper.getResolvedServletMapping(servletContext, "/context/somepath"), is(nullValue())); }
@Test public void shouldResolveFirstServlet() { ServletMapping servletMapping1 = new ServletMappingImpl(Pattern.compile("^/somepath.*$"), SampleServlet.class); ServletMapping servletMapping2 = new ServletMappingImpl(Pattern.compile("^/some.*$"), SampleServlet.class); when(servletContext.getServletMappings()).thenReturn(Arrays.asList(servletMapping1, servletMapping2)); assertThat(servletContextHelper.getResolvedServletMapping(servletContext, "/context/somepathX"), is(servletMapping1)); }