### Question:
ServletMappings { @Nonnull public String getClassForURL(@Nonnull String path) { String servletName = findServletName(path); for (ClassMapping entry : servlets) { if (entry != null && servletName.equals(entry.getServletName())) { return entry.getClassWithPackage(); } } return DEFAULT_SERVLET; } ServletMappings(@Nonnull List<UrlPatternMapping> servletMappings,
                           @Nonnull List<ClassMapping> servlets,
                           @Nonnull CachedDirectory cachedDirectory,
                           @Nonnull Map<String, String> contextParams); @Nullable List<UrlPatternMapping> getServletMappings(); @Nullable List<ClassMapping> getClassMappings(); @Nonnull List<String> getURLPatternsForClass(@Nonnull String classWithPackage); @Nonnull String getClassForURL(@Nonnull String path); @Nonnull FrameworkType guessApplicationType(); final static String DEFAULT_SERVLET; }### Answer:
@Test public void testURLToClassMapping() throws IOException { List<Entry<String,String>> tests; ServletMappings mappings = getTestMappings(); tests = makeMappingsList( "/fruit/summer/index.html", "myservlets.watermelon", "/fruit/summer/index.abc", "myservlets.watermelon", "/seedlist", "myservlets.list", "/seedlist/pear.abc", "myservlets.kiwi", "/seeds", "myservlets.garden", "/seeds/index.html", "myservlets.garden", "/index.abc", "myservlets.kiwi", "/foo/bar/index.html", "myservlets.servlet1", "/foo/bar/index.bop", "myservlets.servlet1", "/baz", "myservlets.servlet2", "/baz/index.html", "myservlets.servlet2", "/catalog", "myservlets.servlet3", "/catalog/index.html", ServletMappings.DEFAULT_SERVLET, "/catalog/racecar.bop", "myservlets.servlet4", "/index.bop", "myservlets.servlet4" ); assertTrue("The wrong number of tests were present", tests.size() == 15); for (Entry<String, String> entry : tests) { String result = mappings.getClassForURL(entry.getKey()); String errorString = "Test failed for " + entry.getKey() + " -> " + entry.getValue() + "\nActual result was " + result; assertTrue(errorString, result.equals(entry.getValue())); } }