01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.apache.roller.util;
20:
21: import junit.framework.Test;
22: import junit.framework.TestCase;
23: import junit.framework.TestSuite;
24:
25: /**
26: * Test regex utils.
27: */
28: public class RegexUtilTest extends TestCase {
29:
30: /**
31: *
32: */
33: public RegexUtilTest() {
34: super ();
35: }
36:
37: /**
38: * @param arg0
39: */
40: public RegexUtilTest(String arg0) {
41: super (arg0);
42: }
43:
44: /**
45: * @see TestCase#setUp()
46: */
47: protected void setUp() throws Exception {
48: super .setUp();
49: }
50:
51: /**
52: * @see TestCase#tearDown()
53: */
54: protected void tearDown() throws Exception {
55: super .tearDown();
56: }
57:
58: public void testEncodingEmail() {
59: // test mailto: escaping
60: String test = "test <a href='mailto:this@email.com'>email</a> string";
61: String expect = "test <a href='mailto:%74%68%69%73%40%65%6d%61%69%6c%2e%63%6f%6d'>email</a> string";
62: String result = RegexUtil.encodeEmail(test);
63: //System.out.println(result);
64: assertEquals(expect, result);
65: }
66:
67: public void testObfuscateEmail() {
68: // test "plaintext" escaping
69: String test = "this@email.com";
70: String expect = "this-AT-email-DOT-com";
71: String result = RegexUtil.encodeEmail(test);
72: assertEquals(expect, result);
73: }
74:
75: public void testHexEmail() {
76: // test hex & obfuscate together
77: String test = "test <a href='mailto:this@email.com'>this@email.com</a> string, and this@email.com";
78: String 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";
79: String result = RegexUtil.encodeEmail(test);
80: //System.out.println(result);
81: assertEquals(expect, result);
82: }
83:
84: public static Test suite() {
85: return new TestSuite(RegexUtilTest.class);
86: }
87:
88: }
|