    1   /*
    2    * Copyright (c) 2001-2003 The XDoclet team
    3    * All rights reserved.
    4    */
    5   package xjavadoc;
    6
    7   import java.io.*;
    8   import junit.framework.*;
    9
    10  /***
    11   * JUnit test for JavaDocReader.
    12   *
    13   * @author      <a href="mailto:aslak.hellesoy@bekk.no">Aslak Hellesøy</a>
    14   * @created     3. januar 2002
    15   * @ejb:bla     bla
    16   * @param what  about this one? Or this one?
    17   * @oh          dear="we" should="go to bed"
    18   */
    19  public class JavaDocReaderTest extends TestCase
    20  {
    21  	private String     javadoc =
    22  		"/********************** This is in the doc too\n" +
    23  		" * JUnit test for\n" +
    24  		"   * JavaDocReader.\n" +
    25  		"     * @ejb:bla * bla\n" +
    26  		" *   @param what about\n" +
    27  		" * this one?\n" +
    28  		" *Or this\n" +
    29  		"     one?\n" +
    30  		" * @oh dear=\"we\" should=\"go to bed\"\n" +
    31  		" */";
    32
    33  	private String     expected =
    34  		"This is in the doc too\n" +
    35  		"JUnit test for\n" +
    36  		"JavaDocReader.\n" +
    37  		"@ejb:bla * bla\n" +
    38  		"@param what about\n" +
    39  		"this one?\n" +
    40  		"Or this\n" +
    41  		"one?\n" +
    42  		"@oh dear=\"we\" should=\"go to bed\"\n";
    43
    44  	public void testRead() throws IOException
    45  	{
    46  		JavaDocReader jr = new JavaDocReader( new StringReader( javadoc ) );
    47  		int i;
    48
    49  		StringWriter w = new StringWriter();
    50
    51  		while( ( i = jr.read() ) != -1 )
    52  		{
    53  			w.write( i );
    54  		}
    55  		w.flush();
    56
    57  		assertEquals( expected, w.toString() );
    58  	}
    59
    60  	public void testReadLine() throws IOException
    61  	{
    62          JavaDocReader jr = new JavaDocReader( new StringReader( javadoc ) );
    63          BufferedReader br = new BufferedReader( jr );
    64          String line;
    65          StringBuffer sb = new StringBuffer();
    66
    67          while( ( line = br.readLine() ) != null )
    68          {
    69              sb.append( line ).append( '\n' );
    70          }
    71
    72          assertEquals( expected, sb.toString() );
    73  	}
    74
    75      public void testNoStarAtEndOfOneLineJavadocWithTag() throws Exception
    76      {
    77          JavaDocReader jr = new JavaDocReader( new StringReader( "/** dum di dum */" ) );
    78          BufferedReader br = new BufferedReader( jr );
    79          assertEquals( "dum di dum ", br.readLine() );
    80      }
    81
    82  }