### Question:
ServletHolderMapper implements Function<ServletDescriptor, ServletHolder> { @Override public ServletHolder apply(ServletDescriptor servletDescriptor) { ServletHolder servletHolder = servletHandler.newServletHolder(Source.EMBEDDED); servletHolder.setHeldClass(servletDescriptor.servletClass()); servletHolder.setName(servletDescriptor.name()); if(servletDescriptor.initParams() != null) { Arrays.stream(servletDescriptor.initParams()) .forEach(p -> servletHolder.setInitParameter(p.name(), p.value())); } for(String pattern : servletDescriptor.urlPatterns()) { servletHandler.addServletWithMapping(servletHolder, pattern); } return servletHolder; } ServletHolderMapper(ServletHandler servletHandler); @Override ServletHolder apply(ServletDescriptor servletDescriptor);  }### Answer:
@Test public void shouldCreateServletHolder() { when(servletHandler.newServletHolder(Source.EMBEDDED)).thenReturn(new ServletHolder(Source.EMBEDDED)); ServletDescriptor servletDescriptor = new ServletDescriptor("name", new String[]{"uri"}, new String[]{"uri"}, 1,null,true, DefaultServlet.class); ServletHolder holder = mapper.apply(servletDescriptor); assertThat(holder.getName()).isEqualTo("name"); assertThat(holder.getClassName()).isEqualTo(DefaultServlet.class.getName()); verify(servletHandler).addServletWithMapping(holder, "uri"); }
@Test public void shouldCreateServletHolderWithParams() { when(servletHandler.newServletHolder(Source.EMBEDDED)).thenReturn(new ServletHolder(Source.EMBEDDED)); ServletDescriptor servletDescriptor = new ServletDescriptor("name", new String[]{"uri"}, new String[]{"uri"}, 1,new WebInitParam[]{new WebParam("key","value")},true, DefaultServlet.class); ServletHolder holder = mapper.apply(servletDescriptor); assertThat(holder.getInitParameters()).isEqualTo(singletonMap("key","value")); }