KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > tagTests > BulletListTagTest


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2003 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/BulletListTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/05/24 16:18:33 $
10
// $Revision: 1.3 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.tests.tagTests;
28
29 import org.htmlparser.Node;
30 import org.htmlparser.tests.ParserTestCase;
31 import org.htmlparser.Text;
32 import org.htmlparser.tags.Bullet;
33 import org.htmlparser.tags.BulletList;
34 import org.htmlparser.tags.CompositeTag;
35 import org.htmlparser.util.NodeList;
36 import org.htmlparser.util.ParserException;
37
38 public class BulletListTagTest extends ParserTestCase
39 {
40     static
41     {
42         System.setProperty ("org.htmlparser.tests.tagTests.BulletListTagTest", "BulletListTagTest");
43     }
44
45     public BulletListTagTest (String JavaDoc name)
46     {
47         super(name);
48     }
49     
50     public void testScan() throws ParserException {
51         createParser(
52             "<ul TYPE=DISC>" +
53                 "<ul TYPE=\"DISC\"><li>Energy supply\n"+
54                     " (Campbell) <A HREF=\"/hansard/37th3rd/h20307p.htm#1646\">1646</A>\n"+
55                     " (MacPhail) <A HREF=\"/hansard/37th3rd/h20307p.htm#1646\">1646</A>\n"+
56                 "</ul><A NAME=\"calpinecorp\"></A><B>Calpine Corp.</B>\n"+
57                 "<ul TYPE=\"DISC\"><li>Power plant projects\n"+
58                     " (Neufeld) <A HREF=\"/hansard/37th3rd/h20314p.htm#1985\">1985</A>\n"+
59                 "</ul>" +
60             "</ul>"
61         );
62         parseAndAssertNodeCount(1);
63
64         NodeList nestedBulletLists =
65             ((CompositeTag)node[0]).searchFor(
66                 BulletList.class,
67                 true
68             );
69         assertEquals(
70             "bullets in first list",
71             2,
72             nestedBulletLists.size()
73         );
74         BulletList firstList =
75             (BulletList)nestedBulletLists.elementAt(0);
76         Bullet firstBullet =
77             (Bullet)firstList.childAt(0);
78         Node firstNodeInFirstBullet =
79             firstBullet.childAt(0);
80         assertType(
81             "first child in bullet",
82             Text.class,
83             firstNodeInFirstBullet
84         );
85         assertStringEquals(
86             "expected text",
87             "Energy supply\n" +
88             " (Campbell) ",
89             firstNodeInFirstBullet.toPlainTextString()
90         );
91     }
92
93     public void testMissingendtag ()
94         throws ParserException
95     {
96         createParser ("<li>item 1<li>item 2");
97         parseAndAssertNodeCount (2);
98         assertStringEquals ("item 1 not correct", "item 1", ((Bullet)node[0]).childAt (0).toHtml ());
99         assertStringEquals ("item 2 not correct", "item 2", ((Bullet)node[1]).childAt (0).toHtml ());
100     }
101 }
102
Popular Tags