1 package org.fhw.cabaweb.junittests;
2
3 import java.util.Locale;
4
5 import org.fhw.cabaweb.tools.StringUtilities;
6
7 import junit.framework.TestCase;
8
9 /***
10 * Klasse für den Test der StringUtilities Methoden
11 *
12 * @author <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
13 * @version Version 1.0 06.07.2004
14 */
15 public class StringUtilitiesTest extends TestCase
16 {
17 public static void main(String[] args)
18 {
19 junit.textui.TestRunner.run(StringUtilitiesTest.class);
20 }
21
22
23
24
25 protected void setUp() throws Exception
26 {
27
28 Locale locale = Locale.getDefault();
29
30
31 Locale.setDefault(Locale.GERMAN);
32
33
34 locale = new Locale("de", "DE");
35 Locale.setDefault(locale);
36
37 super.setUp();
38 }
39
40
41
42
43 protected void tearDown() throws Exception
44 {
45 super.tearDown();
46 }
47
48 public void testIsValidEmailAddress1()
49 {
50 assertEquals(true, StringUtilities.isValidEmailAddress("test@test.com"));
51 assertEquals(true, StringUtilities.isValidEmailAddress("a@b.c"));
52 assertEquals(true, StringUtilities.isValidEmailAddress("a.b@c.d"));
53 assertEquals(true, StringUtilities.isValidEmailAddress("test@217.160.181.179"));
54 assertEquals(true, StringUtilities.isValidEmailAddress("y.Dewey.Marshall.Julie.Amalia.Beth.Darwin.Celina.Bessie.Rita@sleety.6351.pills.biz"));
55 }
56
57 public void testIsValidEmailAddress2()
58 {
59 assertEquals(false, StringUtilities.isValidEmailAddress("a.b@c"));
60 assertEquals(false, StringUtilities.isValidEmailAddress("a@b"));
61 assertEquals(false, StringUtilities.isValidEmailAddress("a"));
62 assertEquals(false, StringUtilities.isValidEmailAddress("@a"));
63 assertEquals(false, StringUtilities.isValidEmailAddress("q@a@com"));
64 }
65
66 public void testToHTMLString1()
67 {
68 String compare = new String("ß");
69 String test = StringUtilities.toHTMLString(compare);
70 assertEquals("ß", test);
71 }
72
73 public void testToHTMLString2()
74 {
75 String compare = new String("äüöÄÜÖ");
76 String test = StringUtilities.toHTMLString(compare);
77 assertEquals("äüöÄÜÖ", test);
78 }
79
80 public void testToHTMLString3()
81 {
82 String compare = new String("<\"1000€\">");
83 String test = StringUtilities.toHTMLString(compare);
84 assertEquals("<"1000€">", test);
85 }
86
87 public void testToHTMLString4()
88 {
89 String compare = new String("\'&\'");
90 String test = StringUtilities.toHTMLString(compare);
91 assertEquals("'&'", test);
92 }
93
94 public void testToHTMLString5()
95 {
96 String compare = new String("\'Test\'\n");
97 String test = StringUtilities.toHTMLString(compare);
98 assertEquals("'Test'<BR/>\n", test);
99 }
100
101 }