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 import java.util.*;
27
28
29
30 /***
31 * Description of the Class
32 *
33 * @author epugh
34 * @created May 3, 2002
35 */
36 public class TestParseUtil extends AbstractTestCase {
37 /***
38 * DOCUMENT ME!
39 *
40 * @throws Exception DOCUMENT ME!
41 */
42 public void testGetEmbeddedString() throws Exception {
43 String s = "ac_update_3_12";
44
45 assertTrue(StringUtil.getEmbeddedString(s, 0, '_').equals("ac"));
46 assertTrue(StringUtil.getEmbeddedString(s, 1, '_').equals("update"));
47 assertTrue(StringUtil.getEmbeddedString(s, 2, '_').equals("3"));
48 assertTrue(StringUtil.getEmbeddedString(s, 3, '_').equals("12"));
49
50
51
52
53
54
55
56
57
58 }
59
60
61 /***
62 * DOCUMENT ME!
63 *
64 * @throws Exception DOCUMENT ME!
65 */
66 public void testGetEmbeddedStringAsInteger() throws Exception {
67 String s = "ac_update_3_12";
68
69 assertTrue(StringUtil.getEmbeddedStringAsInteger(s, 2, '_') == 3);
70 assertTrue(StringUtil.getEmbeddedStringAsInteger(s, 3, '_') == 12);
71
72 try {
73 int i = StringUtil.getEmbeddedStringAsInteger(s, 4, '_');
74 assertTrue("This should not be hit! result:" + i, i == 999);
75 fail("Should not get here, should have exception");
76 } catch (Exception e) {
77 ;
78 }
79 }
80
81
82 /***
83 * DOCUMENT ME!
84 *
85 * @throws Exception DOCUMENT ME!
86 */
87 public void testGetEmbeddedStringWithoutDots() throws Exception {
88 String s = "ac_update_3_12";
89
90 assertTrue(StringUtil.getEmbeddedStringWithoutDots(s, 0, '_').equals("ac"));
91 assertTrue(StringUtil.getEmbeddedStringWithoutDots(s, 1, '_').equals("update"));
92 assertTrue(StringUtil.getEmbeddedStringWithoutDots(s, 2, '_').equals("3"));
93 assertTrue(StringUtil.getEmbeddedStringWithoutDots(s, 3, '_').equals("12"));
94
95
96
97
98
99
100
101
102
103 }
104
105
106 /***
107 * DOCUMENT ME!
108 *
109 * @throws Exception DOCUMENT ME!
110 */
111 public void testSplitString() throws Exception {
112 Vector v = StringUtil.splitString("hello,there,this,is,delimited", ",");
113 assertTrue("Vector must have have 5 elements", v.size() == 5);
114 assertTrue("check elements", v.get(0).toString().equals("hello"));
115 assertTrue("check elements", v.get(1).toString().equals("there"));
116 assertTrue("check elements", v.get(2).toString().equals("this"));
117 assertTrue("check elements", v.get(3).toString().equals("is"));
118 assertTrue("check elements", v.get(4).toString().equals("delimited"));
119 }
120 }