1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.util;
25
26
27
28 /***
29 * Test the Util.java class
30 *
31 * @author epugh
32 * @created May 3, 2002
33 */
34 public class TestUtil extends AbstractTestCase {
35 /***
36 * DOCUMENT ME!
37 *
38 * @throws Exception DOCUMENT ME!
39 */
40 public void testDecode() throws Exception {
41 String SOURCE = "http://www.sun.com?some bogus=value";
42 String ENCODED = "http%3A%2F%2Fwww.sun.com%3Fsome+bogus%3Dvalue";
43
44 String s = ENCODED;
45 s = Util.decode(s, null);
46 assertTrue("Encoded String:" + s, s.equals(SOURCE));
47
48 s = null;
49 s = Util.encode(s, null);
50 assertTrue("S must be null", s == null);
51 }
52
53
54 /***
55 * DOCUMENT ME!
56 *
57 * @throws Exception DOCUMENT ME!
58 */
59 public void testEncode() throws Exception {
60 String SOURCE = "http://www.sun.com?some bogus=value";
61
62 String ENCODED = "http%3A%2F%2Fwww.sun.com%3Fsome+bogus%3Dvalue";
63
64 String s = SOURCE;
65
66 s = Util.encode(s, null);
67
68 assertTrue("Encoded String:" + s, s.equals(ENCODED));
69
70 s = null;
71
72 s = Util.encode(s, null);
73
74 assertTrue("S must be null", s == null);
75 }
76
77
78 /***
79 * DOCUMENT ME!
80 *
81 * @throws Exception DOCUMENT ME!
82 */
83 public void testEncodeDecode() throws Exception {
84 String s = "0%3A7%3A%8A%E1%92%86%82%C9%82%A8%82%A9%82%C8%82%A2-1%3A8%3A%82%AA%82%F1%82%BF%82%E3%82%A4%82%AA%82%C8%82%A2";
85 s = Util.decode(s, "Shift-JIS");
86 System.out.println(s.length() + " " + s);
87 s = "0%3A7%3A%E7%9C%BC%E4%B8%AD%E3%81%AB%E3%81%8A%E3%81%8B%E3%81%AA%E3%81%84-1%3A8%3A%E3%81%8C%E3%82%93%E3%81%A1%E3%82%85%E3%81%86%E3%81%8C%E3%81%AA%E3%81%84";
88 s = Util.decode(s, "UTF-8");
89 System.out.println(s.length() + " " + s);
90 }
91
92
93 /***
94 * A unit test for JUnit
95 *
96 * @exception Exception Description of the Exception
97 */
98 public void testIsNull() throws Exception {
99 boolean result = Util.isNull((String) null);
100 assertTrue("Must be null", result);
101 result = Util.isNull("");
102 assertTrue("Must be null", result);
103 result = Util.isNull("not null");
104 assertTrue("Must not be null", !result);
105 }
106
107
108 }