SnippetMacro macro = new SnippetMacro();
macro.execute( sink, request );
Iterator<SinkEventElement> it = sink.getEventList().iterator();
assertEquals( "verbatim", ( it.next() ).getName() );
SinkEventElement event = it.next();
assertEquals( "text", event.getName() );
String snippet = (String) event.getArgs()[0];
assertEquals( "verbatim_", ( it.next() ).getName() );
assertFalse( it.hasNext() );
assertTrue( snippet.contains( "preamble" ) );
assertTrue( snippet.contains( "first snippet" ) );
assertTrue( snippet.contains( "interlude" ) );
assertTrue( snippet.contains( "second snippet" ) );
assertTrue( snippet.contains( "conclusion" ) );
// again
macroParameters.put( "id", "firstId" );
macroParameters.put( "verbatim", "" );
sink.reset();
request = new MacroRequest( macroParameters, basedir );
macro.execute( sink, request );
it = sink.getEventList().iterator();
assertEquals( "verbatim", ( it.next() ).getName() );
event = it.next();
assertEquals( "text", event.getName() );
snippet = (String) event.getArgs()[0];
assertEquals( "verbatim_", ( it.next() ).getName() );
assertFalse( it.hasNext() );
assertFalse( snippet.contains( "preamble" ) );
assertTrue( snippet.contains( "first snippet" ) );
assertFalse( snippet.contains( "interlude" ) );
assertFalse( snippet.contains( "second snippet" ) );
assertFalse( snippet.contains( "conclusion" ) );
// again
macroParameters.put( "id", "secondId" );
macroParameters.put( "verbatim", "false" );
sink.reset();
request = new MacroRequest( macroParameters, basedir );
macro.execute( sink, request );
it = sink.getEventList().iterator();
event = it.next();
assertEquals( "rawText", event.getName() );
snippet = (String) event.getArgs()[0];
assertFalse( it.hasNext() );
assertFalse( snippet.contains( "preamble" ) );
assertFalse( snippet.contains( "first snippet" ) );
assertFalse( snippet.contains( "interlude" ) );
assertTrue( snippet.contains( "second snippet" ) );
assertFalse( snippet.contains( "conclusion" ) );
// again
macroParameters.put( "id", "thirdId" );
macroParameters.put( "verbatim", "false" );
sink.reset();
request = new MacroRequest( macroParameters, basedir );
macro.execute( sink, request );
it = sink.getEventList().iterator();
event = it.next();
assertEquals( "rawText", event.getName() );
snippet = (String) event.getArgs()[0];
assertFalse( it.hasNext() );
// no need to verify the absence of the first and second snippets if tests above were successful
assertTrue( snippet.contains( "Этот сниппет в формате Unicode (UTF-8)" ) );
}