public void testExecute()
throws MacroExecutionException
{
String sourceContent = "<div><h2>h21</h2><h2>h22</h2><h3>h3</h3><h4>h4</h4><h2>h23</h2></div>";
XhtmlBaseParser parser = new XhtmlBaseParser();
parser.setSecondParsing( true );
Map<String, Object> macroParameters = new HashMap<String, Object>();
macroParameters.put( "parser", parser );
macroParameters.put( "sourceContent", sourceContent );
macroParameters.put( "section", "sec1" );
File basedir = new File( "" );
SinkEventTestingSink sink = new SinkEventTestingSink();
MacroRequest request = new MacroRequest( macroParameters, basedir );
TocMacro macro = new TocMacro();
macro.execute( sink, request );
Iterator<SinkEventElement> it = sink.getEventList().iterator();
assertEquals( "list", ( it.next() ).getName() );
assertEquals( "listItem", ( it.next() ).getName() );
assertEquals( "link", ( it.next() ).getName() );
assertEquals( "text", ( it.next() ).getName() );
assertEquals( "link_", ( it.next() ).getName() );
assertEquals( "listItem_", ( it.next() ).getName() );
assertEquals( "listItem", ( it.next() ).getName() );
assertEquals( "link", ( it.next() ).getName() );
assertEquals( "text", ( it.next() ).getName() );
assertEquals( "link_", ( it.next() ).getName() );
assertEquals( "list", ( it.next() ).getName() );
assertEquals( "listItem", ( it.next() ).getName() );
assertEquals( "link", ( it.next() ).getName() );
assertEquals( "text", ( it.next() ).getName() );
assertEquals( "link_", ( it.next() ).getName() );
assertEquals( "list", ( it.next() ).getName() );
assertEquals( "listItem", ( it.next() ).getName() );
assertEquals( "link", ( it.next() ).getName() );
assertEquals( "text", ( it.next() ).getName() );
assertEquals( "link_", ( it.next() ).getName() );
assertEquals( "listItem_", ( it.next() ).getName() );
assertEquals( "list_", ( it.next() ).getName() );
assertEquals( "listItem_", ( it.next() ).getName() );
assertEquals( "list_", ( it.next() ).getName() );
assertEquals( "listItem_", ( it.next() ).getName() );
assertEquals( "listItem", ( it.next() ).getName() );
assertEquals( "link", ( it.next() ).getName() );
assertEquals( "text", ( it.next() ).getName() );
assertEquals( "link_", ( it.next() ).getName() );
assertEquals( "listItem_", ( it.next() ).getName() );
assertEquals( "list_", ( it.next() ).getName() );
assertFalse( it.hasNext() );
// test parameters
parser = new XhtmlBaseParser();
parser.setSecondParsing( true );
macroParameters.put( "parser", parser );
macroParameters.put( "section", "2" );
macroParameters.put( "fromDepth", "1" );
macroParameters.put( "toDepth", "2" );
macroParameters.put( "class", "myClass" );