1
2
3
4
5 package xjavadoc;
6
7 import java.io.*;
8 import junit.framework.*;
9 import xjavadoc.Token;
10
11 /***
12 * JUnit test for XDoc.
13 *
14 * @author Aslak Hellesøy
15 * @created 3. januar 2002
16 * @ejb:bla bla
17 * @param what about this one? Or this one?
18 * @oh dear="we" should="go to bed"
19 */
20 public class XDocTest extends TestCase
21 {
22
23 private XDoc doc;
24 /***
25 * @param name name of the test
26 */
27 public XDocTest( String name )
28 {
29 super( name );
30 }
31
32 /***
33 * setup doc for testing
34 *
35 * @exception IOException
36 */
37 public void setUp() throws IOException
38 {
39 String javadoc =
40 "/********************** This is in the doc too \n" +
41 " * JUnit test for\n" +
42 " * JavaDocReader. \n" +
43 " * This is sentence number two. \n" +
44 " * @ejb:bla * bla\n" +
45 " * @param what about\n" +
46 " * this one?\n" +
47 " *Or this\n" +
48 " one?\n" +
49 " * @oh dear=\"we\" should=\"go to bed\"\n" +
50 " */";
51
52 Token token = Token.newToken( 0 );
53
54 token.image = javadoc;
55 doc = new XDoc( token, null, null );
56
57 }
58
59 /***
60 * test comment text and first sentence
61 *
62 * @exception IOException Describe the exception
63 */
64 public void testFirstSentence() throws IOException
65 {
66
67 assertEquals( "This is in the doc too JUnit test for JavaDocReader.", doc.getFirstSentence() );
68 assertEquals( "This is in the doc too JUnit test for JavaDocReader. This is sentence number two.", doc.getCommentText() );
69
70 }
71
72 public void testCommentChange() throws IOException
73 {
74 doc.setCommentText( "foo bar baz blurge. And this is second sentence" );
75
76 assertEquals( "foo bar baz blurge.", doc.getFirstSentence() );
77 assertEquals( "foo bar baz blurge. And this is second sentence", doc.getCommentText() );
78
79 }
80
81 public void testTagCreationAndRemoval() throws IOException
82 {
83
84 doc.addTag( "foo:bar", "blurge=\"bang\" baz=\"blabla\" what's up?" );
85
86 assertTrue( doc.hasTag( "foo:bar" ) );
87
88
89 doc.removeTag( doc.getTag( "foo:bar" ) );
90
91 assertTrue( !doc.hasTag( "foo:bar" ) );
92
93 }
94
95 public void testTagChange() throws IOException
96 {
97
98 doc.addTag( "foo:bar", "blurge=\"bang\" baz=\"blabla\" what's up?" );
99
100 assertEquals( doc.getTagAttributeValue( "foo:bar", "blurge" ), "bang" );
101
102 XTag tag = doc.getTag( "foo:bar" );
103
104 tag.setAttribute( "blurge", "foo" );
105 assertEquals( tag.getAttributeValue( "blurge" ), "foo" );
106
107 tag.setAttribute( "foo", "bar" );
108
109 assertEquals( doc.getTagAttributeValue( "foo:bar", "blurge" ), "foo" );
110 assertEquals( doc.getTagAttributeValue( "foo:bar", "foo" ), "bar" );
111
112 }
113 }