View Javadoc
1   package org.apache.maven.doxia.sink.impl;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.CharArrayWriter;
23  import java.io.IOException;
24  import java.io.Writer;
25  
26  import org.apache.maven.doxia.AbstractModuleTest;
27  import org.apache.maven.doxia.logging.PlexusLoggerWrapper;
28  import org.apache.maven.doxia.sink.Sink;
29  import org.apache.maven.doxia.sink.SinkEventAttributes;
30  import org.codehaus.plexus.DefaultPlexusContainer;
31  import org.codehaus.plexus.util.IOUtil;
32  import org.xmlunit.matchers.CompareMatcher;
33  
34  import static org.junit.Assert.assertThat;
35  
36  /**
37   * Abstract base class to test sinks.
38   *
39   * @version $Id$
40   * @since 1.0
41   */
42  public abstract class AbstractSinkTest
43      extends AbstractModuleTest
44  {
45      private final CharArrayWriter testWriter = new CharArrayWriter();
46      private Sink sink;
47  
48      /**
49       * Resets the writer and creates a new sink with it.
50       *
51       * {@inheritDoc}
52       *
53       * @throws java.lang.Exception if something goes wrong.
54       */
55      @Override
56      protected void setUp()
57          throws Exception
58      {
59          super.setUp();
60  
61          testWriter.reset();
62          sink = createSink( testWriter );
63          sink.enableLogging( new PlexusLoggerWrapper( ( ( DefaultPlexusContainer )getContainer() ).getLogger() ) );
64      }
65  
66      /**
67       * Ability to wrap the xmlFragment with a roottag and namespaces, when required
68       *
69       * @param xmlFragment
70       * @return valid XML
71       */
72      protected String wrapXml( String xmlFragment )
73      {
74          return xmlFragment;
75      }
76  
77      /**
78       * Transforms a given string to be compatible to XML comments.
79       *
80       * @param comment The string to transform.
81       *
82       * @return The given string transformed to be compatible to XML comments.
83       *
84       * @see http://www.w3.org/TR/2000/REC-xml-20001006#sec-comments
85       * @since 1.7
86       */
87      protected static String toXmlComment( final String comment )
88      {
89          String processed = comment;
90  
91          if ( processed != null )
92          {
93              while ( processed.contains( "--" ) )
94              {
95                  processed = processed.replace( "--", "- -" );
96              }
97  
98              if ( processed.endsWith( "-" ) )
99              {
100                 processed += " ";
101             }
102         }
103 
104         return processed;
105     }
106 
107     // ---------------------------------------------------------------------
108     // Common test cases
109     // ----------------------------------------------------------------------
110 
111     /**
112      * Tests that the current sink is able to render the common test document. If the sink is an Xml sink defined
113      * by {@link #isXmlSink()}, it uses an Xml Writer defined by {@link #getXmlTestWriter(String)}. If not, it uses
114      * the Writer defined by {@link #getTestWriter(String)}.
115      *
116      * @see SinkTestDocument
117      * @throws IOException If the target test document could not be generated.
118      * @see #isXmlSink()
119      * @see #getTestWriter(String)
120      * @see #getXmlTestWriter(String)
121      */
122     public final void testTestDocument() throws IOException
123     {
124         Writer writer = ( isXmlSink() ? getXmlTestWriter( "testDocument" ) : getTestWriter( "testDocument" ) );
125         Sink testSink = createSink( writer );
126 
127         try
128         {
129             SinkTestDocument.generate( testSink );
130         }
131         finally
132         {
133             testSink.close();
134             IOUtil.close( writer );
135         }
136     }
137 
138     /**
139      * Checks that the sequence <code>[title(), text( title ), title_()]</code>,
140      * invoked on the current sink, produces the same result as
141      * {@link #getTitleBlock getTitleBlock}( title ).
142      */
143     public void testTitle()
144     {
145         String title = "Grodek";
146         sink.title();
147         sink.text( title );
148         sink.title_();
149         sink.flush();
150         sink.close();
151 
152         String actual = testWriter.toString();
153         String expected = getTitleBlock( title );
154 
155         assertEquals( "Wrong title!", expected, actual );
156     }
157 
158     /**
159      * Checks that the sequence <code>[author(), text( author ), author_()]
160      * </code>, invoked on the current sink, produces the same result as
161      * {@link #getAuthorBlock getAuthorBlock}( author ).
162      */
163     public void testAuthor()
164     {
165         String author = "Georg_Trakl";
166         sink.author();
167         sink.text( author );
168         sink.author_();
169         sink.flush();
170         sink.close();
171 
172         String actual = testWriter.toString();
173         String expected = getAuthorBlock( author );
174 
175         assertEquals( "Wrong author!", expected, actual );
176     }
177 
178     /**
179      * Checks that the sequence <code>[date(), text( date ), date_()]</code>,
180      * invoked on the current sink, produces the same result as
181      * {@link #getDateBlock getDateBlock}( date ).
182      */
183     public void testDate()
184     {
185         String date = "1914";
186         sink.date();
187         sink.text( date );
188         sink.date_();
189         sink.flush();
190         sink.close();
191 
192         String actual = testWriter.toString();
193         String expected = getDateBlock( date );
194 
195         assertEquals( "Wrong date!", expected, actual );
196     }
197 
198     /**
199      * Checks that the sequence <code>[head(), head_()]</code>,
200      * invoked on the current sink, produces the same result as
201      * {@link #getHeadBlock getHeadBlock()}.
202      */
203     public void testHead()
204     {
205         sink.head();
206         sink.head_();
207         sink.flush();
208         sink.close();
209 
210         String actual = normalizeLineEnds( testWriter.toString() );
211         String expected = normalizeLineEnds( getHeadBlock() );
212 
213         assertEquals( "Wrong head!", expected, actual );
214     }
215 
216     /**
217      * Checks that the sequence <code>[body(), body_()]</code>,
218      * invoked on the current sink, produces the same result as
219      * {@link #getBodyBlock getBodyBlock()}.
220      */
221     public void testBody()
222     {
223         sink.body();
224         sink.body_();
225         sink.flush();
226         sink.close();
227 
228         String actual = testWriter.toString();
229         String expected = getBodyBlock();
230 
231         assertEquals( "Wrong body!", expected, actual );
232     }
233 
234     /**
235      * Checks that the sequence <code>[sectionTitle(), text( title ),
236      * sectionTitle_()]</code>, invoked on the current sink, produces
237      * the same result as
238      * {@link #getSectionTitleBlock getSectionTitleBlock}( title ).
239      */
240     public void testSectionTitle()
241     {
242         String title = "Title";
243         sink.sectionTitle();
244         sink.text( title );
245         sink.sectionTitle_();
246         sink.flush();
247         sink.close();
248 
249         String actual = testWriter.toString();
250         String expected = getSectionTitleBlock( title );
251 
252         assertEquals( "Wrong sectionTitle!", expected, actual );
253     }
254 
255     /**
256      * Checks that the sequence <code>[section1(), sectionTitle1(),
257      * text( title ), sectionTitle1_(), section1_()]</code>,
258      * invoked on the current sink, produces the same result as
259      * {@link #getSection1Block getSection1Block}( title ).
260      */
261     public void testSection1()
262     {
263         String title = "Title1";
264         sink.section1();
265         sink.sectionTitle1();
266         sink.text( title );
267         sink.sectionTitle1_();
268         sink.section1_();
269         sink.flush();
270         sink.close();
271 
272         String actual = testWriter.toString();
273         String expected = getSection1Block( title );
274 
275         assertEquals( "Wrong section1 block!", expected, actual );
276     }
277 
278     /**
279      * Checks that the sequence <code>[section2(), sectionTitle2(),
280      * text( title ), sectionTitle2_(), section2_()]</code>,
281      * invoked on the current sink, produces the same result as
282      * {@link #getSection2Block getSection2Block}( title ).
283      */
284     public void testSection2()
285     {
286         String title = "Title2";
287         sink.section2();
288         sink.sectionTitle2();
289         sink.text( title );
290         sink.sectionTitle2_();
291         sink.section2_();
292         sink.flush();
293         sink.close();
294 
295         String actual = testWriter.toString();
296         String expected = getSection2Block( title );
297 
298         assertEquals( "Wrong section2 block!", expected, actual );
299     }
300 
301     /**
302      * Checks that the sequence <code>[section3(), sectionTitle3(),
303      * text( title ), sectionTitle3_(), section3_()]</code>,
304      * invoked on the current sink, produces the same result as
305      * {@link #getSection3Block getSection3Block}( title ).
306      */
307     public void testSection3()
308     {
309         String title = "Title3";
310         sink.section3();
311         sink.sectionTitle3();
312         sink.text( title );
313         sink.sectionTitle3_();
314         sink.section3_();
315         sink.flush();
316         sink.close();
317 
318         String actual = testWriter.toString();
319         String expected = getSection3Block( title );
320 
321         assertEquals( "Wrong section3 block!", expected, actual );
322     }
323 
324     /**
325      * Checks that the sequence <code>[section4(), sectionTitle4(),
326      * text( title ), sectionTitle4_(), section4_()]</code>,
327      * invoked on the current sink, produces the same result as
328      * {@link #getSection4Block getSection4Block}( title ).
329      *
330      */
331     public void testSection4()
332     {
333         String title = "Title4";
334         sink.section4();
335         sink.sectionTitle4();
336         sink.text( title );
337         sink.sectionTitle4_();
338         sink.section4_();
339         sink.flush();
340         sink.close();
341 
342         String actual = testWriter.toString();
343         String expected = getSection4Block( title );
344 
345         assertEquals( "Wrong section4 block!", expected, actual );
346     }
347 
348     /**
349      * Checks that the sequence <code>[section5(), sectionTitle5(),
350      * text( title ), sectionTitle5_(), section5_()]</code>,
351      * invoked on the current sink, produces the same result as
352      * {@link #getSection5Block getSection5Block}( title ).
353      */
354     public void testSection5()
355     {
356         String title = "Title5";
357         sink.section5();
358         sink.sectionTitle5();
359         sink.text( title );
360         sink.sectionTitle5_();
361         sink.section5_();
362         sink.flush();
363         sink.close();
364 
365         String actual = testWriter.toString();
366         String expected = getSection5Block( title );
367 
368         assertEquals( "Wrong section5 block!", expected, actual );
369     }
370 
371     /**
372      * Checks that the sequence <code>[list(), listItem(), text( item ),
373      * listItem_(), list_()]</code>, invoked on the current sink, produces
374      * the same result as {@link #getListBlock getListBlock}( item ).
375      *
376      */
377     public void testList()
378     {
379         String item = "list_item";
380         sink.list();
381         sink.listItem();
382         sink.text( item );
383         sink.listItem_();
384         sink.list_();
385         sink.flush();
386         sink.close();
387 
388         String actual = testWriter.toString();
389         String expected = getListBlock( item );
390 
391         assertEquals( "Wrong list!", expected, actual );
392     }
393 
394     /**
395      * Checks that the sequence <code>
396      * [numberedList( Sink.NUMBERING_LOWER_ROMAN ), numberedListItem(),
397      * text( item ), numberedListItem_(), numberedList_()]</code>,
398      * invoked on the current sink, produces the same result as
399      * {@link #getNumberedListBlock getNumberedListBlock}( item ).
400      */
401     public void testNumberedList()
402     {
403         String item = "numbered_list_item";
404         sink.numberedList( Sink.NUMBERING_LOWER_ROMAN );
405         sink.numberedListItem();
406         sink.text( item );
407         sink.numberedListItem_();
408         sink.numberedList_();
409         sink.flush();
410         sink.close();
411 
412         String actual = testWriter.toString();
413         String expected = getNumberedListBlock( item );
414 
415         assertEquals( "Wrong numbered list!", expected, actual );
416     }
417 
418     /**
419      * Checks that the sequence <code>[definitionList(), definitionListItem(),
420      * definedTerm(), text( definum ), definedTerm_(), definition(),
421      * text( definition ), definition_(), definitionListItem_(),
422      * definitionList_()]</code>, invoked on the current sink, produces the same
423      * result as {@link #getDefinitionListBlock getDefinitionListBlock}
424      * ( definum, definition ).
425      */
426     public void testDefinitionList()
427     {
428         String definum = "definum";
429         String definition = "definition";
430         sink.definitionList();
431         sink.definitionListItem();
432         sink.definedTerm();
433         sink.text( definum );
434         sink.definedTerm_();
435         sink.definition();
436         sink.text( definition );
437         sink.definition_();
438         sink.definitionListItem_();
439         sink.definitionList_();
440         sink.flush();
441         sink.close();
442 
443         String actual = testWriter.toString();
444         String expected = getDefinitionListBlock( definum, definition );
445 
446         assertEquals( "Wrong definition list!", expected, actual );
447     }
448 
449     /**
450      * Checks that the sequence <code>[figure(), figureGraphics( source ),
451      * figureCaption(), text( caption ), figureCaption_(), figure_()]</code>,
452      * invoked on the current sink, produces the same result as
453      * {@link #getFigureBlock getFigureBlock}( source, caption ).
454      */
455     public void testFigure() throws Exception
456     {
457         String source = "figure.jpg";
458         String caption = "Figure_caption";
459         sink.figure();
460         sink.figureGraphics( source );
461         sink.figureCaption();
462         sink.text( caption );
463         sink.figureCaption_();
464         sink.figure_();
465         sink.flush();
466         sink.close();
467 
468         String actual = testWriter.toString();
469         String expected = getFigureBlock( source, caption );
470 
471         if ( isXmlSink() )
472         {
473             assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) ));
474         }
475         else
476         {
477             assertEquals( actual, expected );
478         }
479     }
480 
481 
482     public void testFigureWithoutCaption() throws Exception
483     {
484         String source = "figure.jpg";
485         sink.figure();
486         sink.figureGraphics( source );
487         sink.figure_();
488         sink.flush();
489         sink.close();
490 
491         String actual = testWriter.toString();
492         String expected = getFigureBlock( source, null );
493 
494         if ( isXmlSink() )
495         {
496             assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) ));
497         }
498         else
499         {
500             assertEquals( actual, expected );
501         }
502     }
503 
504     /**
505      * Checks that the sequence <code>[table(),
506      * tableRows( Sink.JUSTIFY_CENTER, false ), tableRow(), tableCell(),
507      * text( cell ), tableCell_(), tableRow_(), tableRows_(), tableCaption(),
508      * text( caption ), tableCaption_(), table_()]</code>,
509      * invoked on the current sink, produces the same result as
510      * {@link #getTableBlock getTableBlock}( cell, caption ).
511      */
512     public void testTable() throws Exception
513     {
514         String cell = "cell";
515         String caption = "Table_caption";
516         int[] justify = { Sink.JUSTIFY_CENTER };
517         sink.table();
518         sink.tableRows( justify, false );
519         sink.tableRow();
520         sink.tableCell();
521         sink.text( cell );
522         sink.tableCell_();
523         sink.tableRow_();
524         sink.tableRows_();
525         sink.tableCaption();
526         sink.text( caption );
527         sink.tableCaption_();
528         sink.table_();
529         sink.flush();
530         sink.close();
531 
532         String actual = testWriter.toString();
533         String expected = getTableBlock( cell, caption );
534 
535         if ( isXmlSink() )
536         {
537             assertThat ( wrapXml( actual ), CompareMatcher.isIdenticalTo( wrapXml( expected ) ));
538         }
539         else
540         {
541             assertEquals( actual, expected );
542         }
543     }
544 
545     /**
546      * Checks that the sequence <code>[paragraph(), text( text ),
547      * paragraph_()]</code>, invoked on the current sink, produces
548      * the same result as {@link #getParagraphBlock getParagraphBlock}( text ).
549      */
550     public void testParagraph()
551     {
552         String text = "Text";
553         sink.paragraph();
554         sink.text( text );
555         sink.paragraph_();
556         sink.flush();
557         sink.close();
558 
559         String actual = testWriter.toString();
560         String expected = getParagraphBlock( text );
561 
562         assertEquals( "Wrong paragraph!", expected, actual );
563     }
564 
565     /**
566      * Checks that the sequence <code>[verbatim( SinkEventAttributeSet.BOXED ), text( text ),
567      * verbatim_()]</code>, invoked on the current sink, produces the
568      * same result as {@link #getVerbatimBlock getVerbatimBlock}( text ).
569      */
570     public void testVerbatim()
571     {
572         String text = "Text";
573         sink.verbatim( SinkEventAttributeSet.BOXED );
574         sink.text( text );
575         sink.verbatim_();
576         sink.flush();
577         sink.close();
578 
579         String actual = testWriter.toString();
580         String expected = getVerbatimBlock( text );
581 
582         assertEquals( "Wrong verbatim!", expected, actual );
583     }
584 
585     /**
586      * Checks that the sequence <code>[horizontalRule()]</code>,
587      * invoked on the current sink, produces the same result as
588      * {@link #getHorizontalRuleBlock getHorizontalRuleBlock()}.
589      */
590     public void testHorizontalRule()
591     {
592         sink.horizontalRule();
593         sink.flush();
594         sink.close();
595 
596         String actual = testWriter.toString();
597         String expected = getHorizontalRuleBlock();
598 
599         assertEquals( "Wrong horizontal rule!", expected, actual );
600     }
601 
602     /**
603      * Checks that the sequence <code>[pageBreak()]</code>,
604      * invoked on the current sink, produces the same result as
605      * {@link #getPageBreakBlock getPageBreakBlock()}.
606      */
607     public void testPageBreak()
608     {
609         sink.pageBreak();
610         sink.flush();
611         sink.close();
612 
613         String actual = testWriter.toString();
614         String expected = getPageBreakBlock();
615 
616         assertEquals( "Wrong pageBreak!", expected, actual );
617     }
618 
619     /**
620      * Checks that the sequence <code>[anchor( anchor ), text( anchor ),
621      * anchor_()]</code>, invoked on the current sink, produces the same
622      * result as {@link #getAnchorBlock getAnchorBlock}( anchor ).
623      */
624     public void testAnchor()
625     {
626         String anchor = "Anchor";
627         sink.anchor( anchor );
628         sink.text( anchor );
629         sink.anchor_();
630         sink.flush();
631         sink.close();
632 
633         String actual = testWriter.toString();
634         String expected = getAnchorBlock( anchor );
635 
636         assertEquals( "Wrong anchor!", expected, actual );
637     }
638 
639     /**
640      * Checks that the sequence <code>[link( link ), text( text ),
641      * link_()]</code>, invoked on the current sink, produces the same
642      * result as {@link #getLinkBlock getLinkBlock}( link, text ).
643      */
644     public void testLink()
645     {
646         String link = "#Link";
647         String text = "Text";
648         sink.link( link );
649         sink.text( text );
650         sink.link_();
651         sink.flush();
652         sink.close();
653 
654         String actual = testWriter.toString();
655         String expected = getLinkBlock( link, text );
656 
657         assertEquals( "Wrong link!", expected, actual );
658     }
659 
660     /**
661      * Checks that the sequence <code>[italic(), text( text ), italic_()]</code>,
662      * invoked on the current sink, produces the same result as
663      * {@link #getItalicBlock getItalicBlock}( text ).
664      */
665     public void testItalic()
666     {
667         String text = "Italic";
668         sink.italic();
669         sink.text( text );
670         sink.italic_();
671         sink.flush();
672         sink.close();
673 
674         String actual = testWriter.toString();
675         String expected = getItalicBlock( text );
676 
677         assertEquals( "Wrong italic!", expected, actual );
678     }
679 
680     /**
681      * Checks that the sequence <code>[bold(), text( text ), bold_()]</code>,
682      * invoked on the current sink, produces the same result as
683      * {@link #getBoldBlock getBoldBlock}( text ).
684      */
685     public void testBold()
686     {
687         String text = "Bold";
688         sink.bold();
689         sink.text( text );
690         sink.bold_();
691         sink.flush();
692         sink.close();
693 
694         String actual = testWriter.toString();
695         String expected = getBoldBlock( text );
696 
697         assertEquals( "Wrong bold!", expected, actual );
698     }
699 
700     /**
701      * Checks that the sequence <code>[monospaced(), text( text ),
702      * monospaced_()]</code>, invoked on the current sink, produces the same
703      * result as {@link #getMonospacedBlock getMonospacedBlock}( text ).
704      */
705     public void testMonospaced()
706     {
707         String text = "Monospaced";
708         sink.monospaced();
709         sink.text( text );
710         sink.monospaced_();
711         sink.flush();
712         sink.close();
713 
714         String actual = testWriter.toString();
715         String expected = getMonospacedBlock( text );
716 
717         assertEquals( "Wrong monospaced!", expected, actual );
718     }
719 
720     /**
721      * Checks that the sequence <code>[lineBreak()]</code>,
722      * invoked on the current sink, produces the same result as
723      * {@link #getLineBreakBlock getLineBreakBlock()}.
724      */
725     public void testLineBreak()
726     {
727         sink.lineBreak();
728         sink.flush();
729         sink.close();
730 
731         String actual = testWriter.toString();
732         String expected = getLineBreakBlock();
733 
734         assertEquals( "Wrong lineBreak!", expected, actual );
735     }
736 
737     /**
738      * Checks that the sequence <code>[nonBreakingSpace()]</code>,
739      * invoked on the current sink, produces the same result as
740      * {@link #getNonBreakingSpaceBlock getNonBreakingSpaceBlock()}.
741      */
742     public void testNonBreakingSpace()
743     {
744         sink.nonBreakingSpace();
745         sink.flush();
746         sink.close();
747 
748         String actual = testWriter.toString();
749         String expected = getNonBreakingSpaceBlock();
750 
751         assertEquals( "Wrong nonBreakingSpace!", expected, actual );
752     }
753 
754     /**
755      * Checks that the sequence <code>[text( text )]</code>,
756      * invoked on the current sink, produces the same result as
757      * {@link #getTextBlock getTextBlock()}.
758      */
759     public void testText()
760     {
761         String text = "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
762         sink.text( text );
763         sink.flush();
764         sink.close();
765 
766         String actual = testWriter.toString();
767         String expected = getTextBlock( text );
768 
769         assertEquals( "Wrong text!", expected, actual );
770     }
771 
772     /**
773      * Checks that the sequence <code>[rawText( text )]</code>,
774      * invoked on the current sink, produces the same result as
775      * {@link #getRawTextBlock getRawTextBlock}( text ).
776      */
777     public void testRawText()
778     {
779         String text = "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
780         sink.rawText( text );
781         sink.flush();
782         sink.close();
783 
784         String actual = testWriter.toString();
785         String expected = getRawTextBlock( text );
786 
787         assertEquals( "Wrong rawText!", expected, actual );
788     }
789 
790     /**
791      * Checks that the sequence <code>[comment(comment)]</code>,
792      * invoked on the current sink, produces the same result as
793      * {@link #getCommentBlock getCommentBlock}( comment ).
794      * @since 1.1.1
795      */
796     public void testComment()
797     {
798         String comment = "Simple comment with ----";
799         sink.comment( comment );
800         sink.flush();
801         sink.close();
802 
803         String actual = testWriter.toString();
804         String expected = getCommentBlock( comment );
805 
806         assertEquals( "Wrong comment!", expected, actual );
807 
808         testWriter.reset();
809         sink = createSink( testWriter );
810         sink.enableLogging( new PlexusLoggerWrapper( ( ( DefaultPlexusContainer )getContainer() ).getLogger() ) );
811 
812         comment = "-";
813         sink.comment( comment );
814         sink.flush();
815         sink.close();
816 
817         actual = testWriter.toString();
818         expected = getCommentBlock( comment );
819 
820         assertEquals( "Wrong comment!", expected, actual );
821     }
822 
823     // ----------------------------------------------------------------------
824     // Utility methods
825     // ----------------------------------------------------------------------
826 
827     /**
828      * Returns the sink that is currently being tested.
829      * @return The current test sink.
830      */
831     protected Sink getSink()
832     {
833         return sink;
834     }
835 
836     /**
837      * Returns a String representation of all events that have been written to the sink.
838      * @return The Sink content as a String.
839      */
840     protected String getSinkContent()
841     {
842         return testWriter.toString();
843     }
844 
845     /**
846      * Returns the directory where all sink test output will go.
847      * @return The test output directory.
848      */
849     protected String getOutputDir()
850     {
851         return "sink/";
852     }
853 
854     // ----------------------------------------------------------------------
855     // Abstract methods the individual SinkTests must provide
856     // ----------------------------------------------------------------------
857 
858     /**
859      * This method allows to use the correct Writer in {@link #testTestDocument()}.
860      *
861      * @return <code>true</code> if the Sink is an XML one, <code>false</code> otherwise.
862      * @see #testTestDocument()
863      */
864     protected abstract boolean isXmlSink();
865 
866     /**
867      * Return a new instance of the sink that is being tested.
868      * @param writer The writer for the sink.
869      * @return A new sink.
870      */
871     protected abstract Sink createSink( Writer writer );
872 
873     /**
874      * Returns a title block generated by this sink.
875      * @param title The title to use.
876      * @return The result of invoking a title block on the current sink.
877      * @see #testTitle()
878      */
879     protected abstract String getTitleBlock( String title );
880 
881     /**
882      * Returns an author block generated by this sink.
883      * @param author The author to use.
884      * @return The result of invoking an author block on the current sink.
885      * @see #testAuthor()
886      */
887     protected abstract String getAuthorBlock( String author );
888 
889     /**
890      * Returns a date block generated by this sink.
891      * @param date The date to use.
892      * @return The result of invoking a date block on the current sink.
893      * @see #testDate()
894      */
895     protected abstract String getDateBlock( String date );
896 
897     /**
898      * Returns a head block generated by this sink.
899      * @return The result of invoking a head block on the current sink.
900      * @see #testHead()
901      */
902     protected abstract String getHeadBlock();
903 
904     /**
905      * Returns a body block generated by this sink.
906      * @return The result of invoking a body block on the current sink.
907      * @see #testBody()
908      */
909     protected abstract String getBodyBlock();
910 
911     /**
912      * Returns a SectionTitle block generated by this sink.
913      * @param title The title to use.
914      * @return The result of invoking a SectionTitle block on the current sink.
915      * @see #testSectionTitle()
916      */
917     protected abstract String getSectionTitleBlock( String title );
918 
919     /**
920      * Returns a Section1 block generated by this sink.
921      * @param title The title to use.
922      * @return The result of invoking a Section1 block on the current sink.
923      * @see #testSection1()
924      */
925     protected abstract String getSection1Block( String title );
926 
927     /**
928      * Returns a Section2 block generated by this sink.
929      * @param title The title to use.
930      * @return The result of invoking a Section2 block on the current sink.
931      * @see #testSection2()
932      */
933     protected abstract String getSection2Block( String title );
934 
935     /**
936      * Returns a Section3 block generated by this sink.
937      * @param title The title to use.
938      * @return The result of invoking a Section3 block on the current sink.
939      * @see #testSection3()
940      */
941     protected abstract String getSection3Block( String title );
942 
943     /**
944      * Returns a Section4 block generated by this sink.
945      * @param title The title to use.
946      * @return The result of invoking a Section4 block on the current sink.
947      * @see #testSection4()
948      */
949     protected abstract String getSection4Block( String title );
950 
951     /**
952      * Returns a Section5 block generated by this sink.
953      * @param title The title to use.
954      * @return The result of invoking a Section5 block on the current sink.
955      * @see #testSection5()
956      */
957     protected abstract String getSection5Block( String title );
958 
959     /**
960      * Returns a list block generated by this sink.
961      * @param item The item to use.
962      * @return The result of invoking a list block on the current sink.
963      * @see #testList()
964      */
965     protected abstract String getListBlock( String item );
966 
967     /**
968      * Returns a NumberedList block generated by this sink.
969      * @param item The item to use.
970      * @return The result of invoking a NumberedList block on the current sink.
971      * @see #testNumberedList()
972      */
973     protected abstract String getNumberedListBlock( String item );
974 
975     /**
976      * Returns a DefinitionList block generated by this sink.
977      * @param definum The term to define.
978      * @param definition The definition.
979      * @return The result of invoking a DefinitionList block on the current sink.
980      * @see #testDefinitionList()
981      */
982     protected abstract String getDefinitionListBlock( String definum,
983         String definition );
984 
985     /**
986      * Returns a Figure block generated by this sink.
987      * @param source The figure source string.
988      * @param caption The caption to use (may be null).
989      * @return The result of invoking a Figure block on the current sink.
990      * @see #testFigure()
991      */
992     protected abstract String getFigureBlock( String source, String caption );
993 
994     /**
995      * Returns a Table block generated by this sink.
996      * @param cell A tabel cell to use.
997      * @param caption The caption to use (may be null).
998      * @return The result of invoking a Table block on the current sink.
999      * @see #testTable()
1000      */
1001     protected abstract String getTableBlock( String cell, String caption );
1002 
1003     /**
1004      * Returns a Paragraph block generated by this sink.
1005      * @param text The text to use.
1006      * @return The result of invoking a Paragraph block on the current sink.
1007      * @see #testParagraph()
1008      */
1009     protected abstract String getParagraphBlock( String text );
1010 
1011     /**
1012      * Returns a Verbatim block generated by this sink.
1013      * @param text The text to use.
1014      * @return The result of invoking a Verbatim block on the current sink.
1015      * @see #testVerbatim()
1016      */
1017     protected abstract String getVerbatimBlock( String text );
1018 
1019     /**
1020      * Returns a HorizontalRule block generated by this sink.
1021      * @return The result of invoking a HorizontalRule block on the current sink.
1022      * @see #testHorizontalRule()
1023      */
1024     protected abstract String getHorizontalRuleBlock();
1025 
1026     /**
1027      * Returns a PageBreak block generated by this sink.
1028      * @return The result of invoking a PageBreak block on the current sink.
1029      * @see #testPageBreak()
1030      */
1031     protected abstract String getPageBreakBlock();
1032 
1033     /**
1034      * Returns a Anchor block generated by this sink.
1035      * @param anchor The anchor to use.
1036      * @return The result of invoking a Anchor block on the current sink.
1037      * @see #testAnchor()
1038      */
1039     protected abstract String getAnchorBlock( String anchor );
1040 
1041     /**
1042      * Returns a Link block generated by this sink.
1043      * @param link The link to use.
1044      * @param text The link text.
1045      * @return The result of invoking a Link block on the current sink.
1046      * @see #testLink()
1047      */
1048     protected abstract String getLinkBlock( String link, String text );
1049 
1050     /**
1051      * Returns a Italic block generated by this sink.
1052      * @param text The text to use.
1053      * @return The result of invoking a Italic block on the current sink.
1054      * @see #testItalic()
1055      */
1056     protected abstract String getItalicBlock( String text );
1057 
1058     /**
1059      * Returns a Bold block generated by this sink.
1060      * @param text The text to use.
1061      * @return The result of invoking a Bold block on the current sink.
1062      * @see #testBold()
1063      */
1064     protected abstract String getBoldBlock( String text );
1065 
1066     /**
1067      * Returns a Monospaced block generated by this sink.
1068      * @param text The text to use.
1069      * @return The result of invoking a Monospaced block on the current sink.
1070      * @see #testMonospaced()
1071      */
1072     protected abstract String getMonospacedBlock( String text );
1073 
1074     /**
1075      * Returns a LineBreak block generated by this sink.
1076      * @return The result of invoking a LineBreak block on the current sink.
1077      * @see #testLineBreak()
1078      */
1079     protected abstract String getLineBreakBlock();
1080 
1081     /**
1082      * Returns a NonBreakingSpace block generated by this sink.
1083      * @return The result of invoking a NonBreakingSpace block
1084      * on the current sink.
1085      * @see #testNonBreakingSpace()
1086      */
1087     protected abstract String getNonBreakingSpaceBlock();
1088 
1089     /**
1090      * Returns a Text block generated by this sink.
1091      * @param text The text to use.
1092      * @return The result of invoking a Text block on the current sink.
1093      * @see #testText()
1094      */
1095     protected abstract String getTextBlock( String text );
1096 
1097     /**
1098      * Returns a RawText block generated by this sink.
1099      * @param text The text to use.
1100      * @return The result of invoking a RawText block on the current sink.
1101      * @see #testRawText()
1102      */
1103     protected abstract String getRawTextBlock( String text );
1104 
1105     /**
1106      * Returns a comment block generated by this sink.
1107      * @param text The text to use.
1108      * @return The result of invoking a comment block on the current sink.
1109      * @see #testComment()
1110      * @since 1.1.1
1111      */
1112     protected abstract String getCommentBlock( String text );
1113 
1114     protected final void verifyValignSup( String text )
1115     {
1116         sink.text( "ValignSup", new SinkEventAttributeSet( SinkEventAttributes.VALIGN, "sup"  ) );
1117         sink.flush();
1118         sink.close();
1119 
1120         String actual = testWriter.toString();
1121 
1122         assertEquals( "Wrong valign sup!", text, actual );
1123     }
1124 
1125     protected final void verifyValignSub( String text )
1126     {
1127         sink.text( "ValignSub", new SinkEventAttributeSet( SinkEventAttributes.VALIGN, "sub"  ) );
1128         sink.flush();
1129         sink.close();
1130 
1131         String actual = testWriter.toString();
1132 
1133         assertEquals( "Wrong valign sub!", text, actual );
1134     }
1135 
1136     protected final void verifyDecorationUnderline( String text )
1137     {
1138         sink.text( "DecorationUnderline", new SinkEventAttributeSet( SinkEventAttributes.DECORATION, "underline"  ) );
1139         sink.flush();
1140         sink.close();
1141 
1142         String actual = testWriter.toString();
1143 
1144         assertEquals( "Wrong decoration underline!", text, actual );
1145     }
1146 
1147     protected final void verifyDecorationLineThrough( String text )
1148     {
1149         sink.text( "DecorationLineThrough", new SinkEventAttributeSet( SinkEventAttributes.DECORATION, "line-through"  ) );
1150         sink.flush();
1151         sink.close();
1152 
1153         String actual = testWriter.toString();
1154 
1155         assertEquals( "Wrong decoration line-through!", text, actual );
1156     }
1157 
1158 
1159 }