### Question:
UrlRewriteRulesDescriptorFactory { public static UrlRewriteRulesDescriptor load( String format, Reader reader ) throws IOException { UrlRewriteRulesImporter importer = IMPORTERS.get( format ); if( importer == null ) { throw new IllegalArgumentException( RES.noImporterForFormat( format ) ); } return importer.load( reader ); } private  UrlRewriteRulesDescriptorFactory(); static UrlRewriteRulesDescriptor create(); static UrlRewriteRulesDescriptor load( String format, Reader reader ); static void store( UrlRewriteRulesDescriptor descriptor, String format, Writer writer );  }### Answer:
@Test public void testLoadMissingFile() throws IOException { try { UrlRewriteRulesDescriptorFactory.load( "xml", getTestResourceReader( "missing.xml" ) ); fail( "Should have thrown a FileNotFoundException." ); } catch ( FileNotFoundException e ) { assertThat( e.getMessage(), containsString( "missing.xml" ) ); } }
@Test public void testLoadEmptyFile() { Logger logger = org.apache.log4j.LogManager.getLogger( "org.apache.commons.digester3.Digester" ); Level level = logger.getLevel(); try { logger.setLevel( org.apache.log4j.Level.OFF ); UrlRewriteRulesDescriptorFactory.load( "xml", getTestResourceReader( "empty.xml" ) ); fail( "Should have thrown an IOException." ); } catch ( IOException e ) { assertEquals("org.xml.sax.SAXParseException; lineNumber: 16; " + "columnNumber: 4; Premature end of file.", e.getMessage()); } catch ( Throwable t ) { fail( "Should have thrown an IOException." ); } finally { logger.setLevel( level ); } }
@Test public void testLoadInvalidFile() { Logger logger = org.apache.log4j.LogManager.getLogger( "org.apache.commons.digester3.Digester" ); Level level = logger.getLevel(); try { logger.setLevel( org.apache.log4j.Level.OFF ); UrlRewriteRulesDescriptorFactory.load( "xml", getTestResourceReader( "invalid.xml" ) ); fail( "Should have thrown an IOException." ); } catch ( IOException e ) { assertEquals("org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 2; " + "The markup in the document preceding the root element must be well-formed.", e.getMessage()); } catch ( Throwable t ) { fail( "Should have thrown an IOException." ); } finally { logger.setLevel( level ); } }
@Test public void testLoadNoopFile() throws IOException { UrlRewriteRulesDescriptor config = UrlRewriteRulesDescriptorFactory.load( "xml", getTestResourceReader( "noop.xml" ) ); assertThat( "Rules should be an empty list.", config.getRules().isEmpty(), Matchers.is( true ) ); }
@Test public void testLoadSimpleFile() throws IOException { UrlRewriteRulesDescriptor config = UrlRewriteRulesDescriptorFactory.load( "xml", getTestResourceReader( "simple.xml" ) ); assertThat( "Failed to load simple config file.", config, notNullValue() ); }
@Test public void testLoadSimpleFilterFile() throws IOException { UrlRewriteRulesDescriptor config = UrlRewriteRulesDescriptorFactory.load( "xml", getTestResourceReader( "filter-simple.xml" ) ); List<UrlRewriteFilterDescriptor> filters = config.getFilters(); assertThat( filters.size(), is( 1 ) ); UrlRewriteFilterDescriptor filter = config.getFilter( "test-filter-1" ); assertThat( filter, notNullValue() ); assertThat( config.getFilters().get(0), sameInstance( filter ) ); }