KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > util > UtilitiesTest


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 /*
19  * Created on Nov 2, 2003
20  */

21 package org.apache.roller.util;
22
23
24 import junit.framework.Test;
25 import junit.framework.TestCase;
26 import junit.framework.TestSuite;
27 import org.apache.roller.ui.rendering.model.UtilitiesModel;
28
29 /**
30  * @author lance
31  */

32 public class UtilitiesTest extends TestCase
33 {
34     /**
35      * Constructor for LinkbackExtractorTest.
36      * @param arg0
37      */

38     public UtilitiesTest(String JavaDoc arg0)
39     {
40         super(arg0);
41     }
42
43     public static void main(String JavaDoc[] args)
44     {
45     }
46
47     /**
48      * @see TestCase#setUp()
49      */

50     protected void setUp() throws Exception JavaDoc
51     {
52         super.setUp();
53     }
54
55     /**
56      * @see TestCase#tearDown()
57      */

58     protected void tearDown() throws Exception JavaDoc
59     {
60         super.tearDown();
61     }
62     
63     public void testExtractHTML()
64     {
65         String JavaDoc test = "<a>keep me</a>";
66         String JavaDoc expect = "<a></a>";
67         String JavaDoc result = Utilities.extractHTML(test);
68         assertEquals(expect, result);
69     }
70     
71     public void testRemoveHTML()
72     {
73         String JavaDoc test = "<br><br><p>a <b>bold</b> sentence with a <a HREF=\"http://example.com\">link</a></p>";
74         String JavaDoc expect = "a bold sentence with a link";
75         String JavaDoc result = Utilities.removeHTML(test, false);
76         assertEquals(expect, result);
77     }
78         
79     public void testTruncateNicely1()
80     {
81         String JavaDoc test = "blah blah blah blah blah";
82         String JavaDoc expect = "blah blah blah";
83         String JavaDoc result = Utilities.truncateNicely(test, 11, 15, "");
84         assertEquals(expect, result);
85     }
86     
87     public void testTruncateNicely2()
88     {
89         String JavaDoc test = "<p><b>blah1 blah2</b> <i>blah3 blah4 blah5</i></p>";
90         String JavaDoc expect = "<p><b>blah1 blah2</b> <i>blah3</i></p>";
91         String JavaDoc result = Utilities.truncateNicely(test, 15, 20, "");
92         //System.out.println(result);
93
assertEquals(expect, result);
94     }
95
96     public void testAddNoFollow() {
97         String JavaDoc test1 = "<p>this some text with a <a HREF=\"http://example.com\">link</a>";
98         String JavaDoc expect1 = "<p>this some text with a <a HREF=\"http://example.com\" rel=\"nofollow\">link</a>";
99         String JavaDoc result1 = UtilitiesModel.addNofollow(test1);
100         assertEquals(expect1, result1);
101
102         String JavaDoc test2 = "<p>this some text with a <A HREF=\"http://example.com\">link</a>";
103         String JavaDoc expect2 = "<p>this some text with a <A HREF=\"http://example.com\" rel=\"nofollow\">link</a>";
104         String JavaDoc result2 = UtilitiesModel.addNofollow(test2);
105         assertEquals(expect2, result2);
106
107     }
108
109     public static Test suite()
110     {
111         return new TestSuite(UtilitiesTest.class);
112     }
113 }
114
Popular Tags