KickJava   Java API By Example, From Geeks To Geeks.

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


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 8, 2003
20  */

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

32 public class RegexUtilTest extends TestCase
33 {
34
35     /**
36      *
37      */

38     public RegexUtilTest()
39     {
40         super();
41     }
42
43     /**
44      * @param arg0
45      */

46     public RegexUtilTest(String JavaDoc arg0)
47     {
48         super(arg0);
49     }
50
51     /**
52      * @see TestCase#setUp()
53      */

54     protected void setUp() throws Exception JavaDoc
55     {
56         super.setUp();
57     }
58
59     /**
60      * @see TestCase#tearDown()
61      */

62     protected void tearDown() throws Exception JavaDoc
63     {
64         super.tearDown();
65     }
66     
67     public void testEncodingEmail()
68     {
69         // test mailto: escaping
70
String JavaDoc test = "test <a HREF='mailto:this@email.com'>email</a> string";
71         String JavaDoc expect = "test <a HREF='mailto:%74%68%69%73%40%65%6d%61%69%6c%2e%63%6f%6d'>email</a> string";
72         String JavaDoc result = RegexUtil.encodeEmail(test) ;
73         //System.out.println(result);
74
assertEquals(expect, result);
75     }
76     
77     public void testObfuscateEmail()
78     {
79         // test "plaintext" escaping
80
String JavaDoc test = "this@email.com";
81         String JavaDoc expect = "this-AT-email-DOT-com";
82         String JavaDoc result = RegexUtil.encodeEmail(test);
83         assertEquals(expect, result);
84     }
85     
86     public void testHexEmail()
87     {
88         // test hex & obfuscate together
89
String JavaDoc test = "test <a HREF='mailto:this@email.com'>this@email.com</a> string, and this@email.com";
90         String JavaDoc expect = "test <a HREF='mailto:%74%68%69%73%40%65%6d%61%69%6c%2e%63%6f%6d'>this-AT-email-DOT-com</a> string, and this-AT-email-DOT-com";
91         String JavaDoc result = RegexUtil.encodeEmail(test);
92         //System.out.println(result);
93
assertEquals(expect, result);
94     }
95
96     public static Test suite()
97     {
98         return new TestSuite(RegexUtilTest.class);
99     }}
100
Popular Tags