### Question:
PrettyConfigurator { public PrettyConfig configure() throws IOException, SAXException { final PrettyConfigBuilder builder = new PrettyConfigBuilder(); feedClassLoaderConfigs(builder); feedContextSpecifiedConfig(builder); feedWebAppConfig(builder); return builder.build(); } PrettyConfigurator(final ServletContext servletContext); PrettyConfig configure(); static final String PRETTY_CONFIG_RESOURCE; static final String DEFAULT_PRETTY_FACES_CONFIG; }### Answer:
@Test public void configureSpecial() throws SAXException, IOException { final ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class); EasyMock.expect(servletContext.getInitParameter(PrettyFilter.CONFIG_FILES_ATTR)).andReturn("car.xml, cdr.xml") .anyTimes(); EasyMock.expect(servletContext.getResourceAsStream("car.xml")).andReturn(mockPrettyConfigInputStream()) .anyTimes(); EasyMock.expect(servletContext.getResourceAsStream("cdr.xml")).andReturn(mockPrettyConfigInputStream()) .anyTimes(); EasyMock.expect(servletContext.getResourceAsStream(PrettyConfigurator.DEFAULT_PRETTY_FACES_CONFIG)).andReturn( mockPrettyConfigInputStream()).anyTimes(); final PrettyConfigurator configurator = new PrettyConfigurator(servletContext); EasyMock.replay(servletContext); final PrettyConfig config = configurator.configure(); Assert.assertEquals(24, config.getMappings().size()); }
@Test public void configureDefault() throws SAXException, IOException { final ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class); EasyMock.expect(servletContext.getInitParameter(PrettyFilter.CONFIG_FILES_ATTR)).andReturn(null).anyTimes(); EasyMock.expect(servletContext.getResourceAsStream(PrettyConfigurator.DEFAULT_PRETTY_FACES_CONFIG)).andReturn( null).anyTimes(); final ClassLoader resourceLoader = new URLClassLoader(new URL[0], Thread.currentThread() .getContextClassLoader()) { @Override public Enumeration<URL> getResources(final String name) throws IOException { if (PrettyConfigurator.PRETTY_CONFIG_RESOURCE.equals(name)) { return enumeration(mockPrettyConfigURL()); } else { return super.getResources(name); } } }; final PrettyConfigurator configurator = new PrettyConfigurator(servletContext) { @Override protected ClassLoader getResourceLoader() { return resourceLoader; } }; EasyMock.replay(servletContext); final PrettyConfig config = configurator.configure(); Assert.assertEquals(8, config.getMappings().size()); }