1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import static org.testng.AssertJUnit.assertEquals; |
24 |
|
import static org.testng.AssertJUnit.assertNull; |
25 |
|
import static org.testng.AssertJUnit.assertTrue; |
26 |
|
|
27 |
|
import jalview.gui.JvOptionPane; |
28 |
|
|
29 |
|
import java.util.ArrayList; |
30 |
|
import java.util.Arrays; |
31 |
|
import java.util.List; |
32 |
|
|
33 |
|
import org.testng.annotations.BeforeClass; |
34 |
|
import org.testng.annotations.Test; |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (128) |
Complexity: 13 |
Complexity Density: 0.11 |
|
36 |
|
public class StringUtilsTest |
37 |
|
{ |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
39 |
1 |
@BeforeClass(alwaysRun = true)... |
40 |
|
public void setUpJvOptionPane() |
41 |
|
{ |
42 |
1 |
JvOptionPane.setInteractiveMode(false); |
43 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
44 |
|
} |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
46 |
1 |
@Test(groups = { "Functional" })... |
47 |
|
public void testInsertCharAt() |
48 |
|
{ |
49 |
1 |
char[] c1 = "ABC".toCharArray(); |
50 |
1 |
char[] expected = new char[] { 'A', 'B', 'C', 'w', 'w' }; |
51 |
1 |
assertTrue(Arrays.equals(expected, |
52 |
|
StringUtils.insertCharAt(c1, 3, 2, 'w'))); |
53 |
1 |
expected = new char[] { 'A', 'B', 'C', 'w', 'w' }; |
54 |
1 |
assertTrue(Arrays.equals(expected, |
55 |
|
StringUtils.insertCharAt(c1, 4, 2, 'w'))); |
56 |
1 |
assertTrue(Arrays.equals(expected, |
57 |
|
StringUtils.insertCharAt(c1, 5, 2, 'w'))); |
58 |
1 |
assertTrue(Arrays.equals(expected, |
59 |
|
StringUtils.insertCharAt(c1, 6, 2, 'w'))); |
60 |
1 |
assertTrue(Arrays.equals(expected, |
61 |
|
StringUtils.insertCharAt(c1, 7, 2, 'w'))); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
64 |
1 |
@Test(groups = { "Functional" })... |
65 |
|
public void testDeleteChars() |
66 |
|
{ |
67 |
1 |
char[] c1 = "ABC".toCharArray(); |
68 |
|
|
69 |
|
|
70 |
1 |
assertTrue( |
71 |
|
Arrays.equals(new char[] |
72 |
|
{ 'A', 'C' }, StringUtils.deleteChars(c1, 1, 2))); |
73 |
|
|
74 |
|
|
75 |
1 |
assertTrue( |
76 |
|
Arrays.equals(new char[] |
77 |
|
{ 'C' }, StringUtils.deleteChars(c1, 0, 2))); |
78 |
|
|
79 |
|
|
80 |
1 |
assertTrue(Arrays.equals(new char[] {}, |
81 |
|
StringUtils.deleteChars(c1, 0, 3))); |
82 |
|
|
83 |
|
|
84 |
1 |
assertTrue( |
85 |
|
Arrays.equals(new char[] |
86 |
|
{ 'A', 'B' }, StringUtils.deleteChars(c1, 2, 3))); |
87 |
|
|
88 |
|
|
89 |
1 |
assertTrue(Arrays.equals(c1, StringUtils.deleteChars(c1, 3, 4))); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
92 |
1 |
@Test(groups = { "Functional" })... |
93 |
|
public void testGetLastToken() |
94 |
|
{ |
95 |
1 |
assertNull(StringUtils.getLastToken(null, null)); |
96 |
1 |
assertNull(StringUtils.getLastToken(null, "/")); |
97 |
1 |
assertEquals("a", StringUtils.getLastToken("a", null)); |
98 |
|
|
99 |
1 |
assertEquals("abc", StringUtils.getLastToken("abc", "/")); |
100 |
1 |
assertEquals("c", StringUtils.getLastToken("abc", "b")); |
101 |
1 |
assertEquals("file1.dat", StringUtils.getLastToken( |
102 |
|
"file://localhost:8080/data/examples/file1.dat", "/")); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
105 |
1 |
@Test(groups = { "Functional" })... |
106 |
|
public void testSeparatorListToArray() |
107 |
|
{ |
108 |
1 |
String[] result = StringUtils.separatorListToArray( |
109 |
|
"foo=',',min='foo',max='1,2,3',fa=','", ","); |
110 |
1 |
assertEquals("[foo=',', min='foo', max='1,2,3', fa=',']", |
111 |
|
Arrays.toString(result)); |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
1 |
result = StringUtils.separatorListToArray("minsize='2', sep=','", ","); |
116 |
1 |
assertEquals("[minsize='2', sep=',']", Arrays.toString(result)); |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
1 |
assertEquals("[abc='|'d, ef, g]", Arrays.toString( |
123 |
|
StringUtils.separatorListToArray("abc='|'d|ef|g", "|"))); |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
126 |
1 |
@Test(groups = { "Functional" })... |
127 |
|
public void testArrayToSeparatorList() |
128 |
|
{ |
129 |
1 |
assertEquals("*", StringUtils.arrayToSeparatorList(null, "*")); |
130 |
1 |
assertEquals("*", |
131 |
|
StringUtils.arrayToSeparatorList(new String[] {}, "*")); |
132 |
1 |
assertEquals("a*bc*cde", |
133 |
|
StringUtils.arrayToSeparatorList(new String[] |
134 |
|
{ "a", "bc", "cde" }, "*")); |
135 |
1 |
assertEquals("a*cde", |
136 |
|
StringUtils.arrayToSeparatorList(new String[] |
137 |
|
{ "a", null, "cde" }, "*")); |
138 |
1 |
assertEquals("a**cde", |
139 |
|
StringUtils.arrayToSeparatorList(new String[] |
140 |
|
{ "a", "", "cde" }, "*")); |
141 |
|
|
142 |
1 |
assertEquals("a*b*c*cde", |
143 |
|
StringUtils.arrayToSeparatorList(new String[] |
144 |
|
{ "a", "b*c", "cde" }, "*")); |
145 |
|
} |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
147 |
1 |
@Test(groups = { "Functional" })... |
148 |
|
public void testListToDelimitedString() |
149 |
|
{ |
150 |
1 |
assertEquals("", StringUtils.listToDelimitedString(null, ";")); |
151 |
1 |
List<String> list = new ArrayList<>(); |
152 |
1 |
assertEquals("", StringUtils.listToDelimitedString(list, ";")); |
153 |
1 |
list.add("now"); |
154 |
1 |
assertEquals("now", StringUtils.listToDelimitedString(list, ";")); |
155 |
1 |
list.add("is"); |
156 |
1 |
assertEquals("now;is", StringUtils.listToDelimitedString(list, ";")); |
157 |
1 |
assertEquals("now ; is", |
158 |
|
StringUtils.listToDelimitedString(list, " ; ")); |
159 |
1 |
list.add("the"); |
160 |
1 |
list.add("winter"); |
161 |
1 |
list.add("of"); |
162 |
1 |
list.add("our"); |
163 |
1 |
list.add("discontent"); |
164 |
1 |
assertEquals("now is the winter of our discontent", |
165 |
|
StringUtils.listToDelimitedString(list, " ")); |
166 |
|
} |
167 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
168 |
1 |
@Test(groups = { "Functional" })... |
169 |
|
public void testParseInt() |
170 |
|
{ |
171 |
1 |
assertEquals(0, StringUtils.parseInt(null)); |
172 |
1 |
assertEquals(0, StringUtils.parseInt("")); |
173 |
1 |
assertEquals(0, StringUtils.parseInt("x")); |
174 |
1 |
assertEquals(0, StringUtils.parseInt("1.2")); |
175 |
1 |
assertEquals(33, StringUtils.parseInt("33")); |
176 |
1 |
assertEquals(33, StringUtils.parseInt("+33")); |
177 |
1 |
assertEquals(-123, StringUtils.parseInt("-123")); |
178 |
|
|
179 |
1 |
assertEquals(0, |
180 |
|
StringUtils.parseInt(String.valueOf(Integer.MAX_VALUE) + "1")); |
181 |
|
} |
182 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
183 |
1 |
@Test(groups = { "Functional" })... |
184 |
|
public void testCompareVersions() |
185 |
|
{ |
186 |
1 |
assertEquals(0, StringUtils.compareVersions(null, null)); |
187 |
1 |
assertEquals(0, StringUtils.compareVersions("2.8.3", null)); |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
1 |
assertEquals(0, StringUtils.compareVersions("2.8", "2.8")); |
193 |
1 |
assertEquals(0, StringUtils.compareVersions("2.8.3", "2.8.3")); |
194 |
1 |
assertEquals(0, StringUtils.compareVersions("2.8.3b1", "2.8.3b1", "b")); |
195 |
1 |
assertEquals(0, StringUtils.compareVersions("2.8.3B1", "2.8.3b1", "b")); |
196 |
1 |
assertEquals(0, StringUtils.compareVersions("2.8.3b1", "2.8.3B1", "b")); |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
1 |
assertEquals(-1, StringUtils.compareVersions("2.8.3", "2.8.4")); |
202 |
1 |
assertEquals(-1, StringUtils.compareVersions("2.8.3", "2.9")); |
203 |
1 |
assertEquals(-1, StringUtils.compareVersions("2.8.3", "2.9.2")); |
204 |
1 |
assertEquals(-1, StringUtils.compareVersions("2.8", "2.8.3")); |
205 |
1 |
assertEquals(-1, StringUtils.compareVersions("2.8.3", "2.8.3b1", "b")); |
206 |
1 |
assertEquals(-1, |
207 |
|
StringUtils.compareVersions("2.8.3b1", "2.8.3b2", "b")); |
208 |
1 |
assertEquals(-1, StringUtils.compareVersions("2.8", "2.8.0", "b")); |
209 |
1 |
assertEquals(-1, StringUtils.compareVersions("2", "12")); |
210 |
1 |
assertEquals(-1, StringUtils.compareVersions("3.2.4", "3.12.11")); |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
1 |
assertEquals(1, StringUtils.compareVersions("2.8.3", "2.8")); |
216 |
1 |
assertEquals(1, StringUtils.compareVersions("2.8.0", "2.8")); |
217 |
1 |
assertEquals(1, StringUtils.compareVersions("2.8.4", "2.8.3")); |
218 |
1 |
assertEquals(1, StringUtils.compareVersions("2.8.3b1", "2.8.3", "b")); |
219 |
1 |
assertEquals(1, StringUtils.compareVersions("2.8.3", "2.8.2b1", "b")); |
220 |
1 |
assertEquals(1, StringUtils.compareVersions("2.8.0b2", "2.8.0b1", "b")); |
221 |
1 |
assertEquals(1, StringUtils.compareVersions("12", "2")); |
222 |
1 |
assertEquals(1, StringUtils.compareVersions("3.12.11", "3.2.4")); |
223 |
|
} |
224 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
225 |
1 |
@Test(groups = { "Functional" })... |
226 |
|
public void testToSentenceCase() |
227 |
|
{ |
228 |
1 |
assertEquals("John", StringUtils.toSentenceCase("john")); |
229 |
1 |
assertEquals("John", StringUtils.toSentenceCase("JOHN")); |
230 |
1 |
assertEquals("John and james", |
231 |
|
StringUtils.toSentenceCase("JOHN and JAMES")); |
232 |
1 |
assertEquals("J", StringUtils.toSentenceCase("j")); |
233 |
1 |
assertEquals("", StringUtils.toSentenceCase("")); |
234 |
1 |
assertNull(StringUtils.toSentenceCase(null)); |
235 |
|
} |
236 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
237 |
1 |
@Test(groups = { "Functional" })... |
238 |
|
public void testStripHtmlTags() |
239 |
|
{ |
240 |
1 |
assertNull(StringUtils.stripHtmlTags(null)); |
241 |
1 |
assertEquals("", StringUtils.stripHtmlTags("")); |
242 |
1 |
assertEquals("<a href=\"something\">label</href>", |
243 |
|
StringUtils.stripHtmlTags( |
244 |
|
"<html><a href=\"something\">label</href></html>")); |
245 |
|
|
246 |
|
|
247 |
1 |
assertEquals("<a href=\"something\">label</href>", |
248 |
|
StringUtils |
249 |
|
.stripHtmlTags("<a href=\"something\">label</href>")); |
250 |
|
|
251 |
|
|
252 |
1 |
assertEquals("<body><p>hello", StringUtils |
253 |
|
.stripHtmlTags("<html><body><p>hello</body></html>")); |
254 |
|
|
255 |
1 |
assertEquals("kdHydro < 12.53", |
256 |
|
StringUtils.stripHtmlTags("kdHydro < 12.53")); |
257 |
|
} |
258 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
259 |
1 |
@Test(groups = { "Functional" })... |
260 |
|
public void testUrlEncode() |
261 |
|
{ |
262 |
|
|
263 |
1 |
assertNull(StringUtils.urlEncode(null, ";,")); |
264 |
1 |
assertEquals("", StringUtils.urlEncode("", "")); |
265 |
1 |
assertEquals("", StringUtils.urlEncode("", ";,")); |
266 |
|
|
267 |
|
|
268 |
|
|
269 |
1 |
assertEquals("+", StringUtils.urlEncode(" ", " ")); |
270 |
1 |
assertEquals("%25", StringUtils.urlEncode("%", "%")); |
271 |
1 |
assertEquals(".", StringUtils.urlEncode(".", ".")); |
272 |
1 |
assertEquals("%3A", StringUtils.urlEncode(":", ":")); |
273 |
1 |
assertEquals("%3B", StringUtils.urlEncode(";", ";")); |
274 |
1 |
assertEquals("%3D", StringUtils.urlEncode("=", "=")); |
275 |
1 |
assertEquals("%2C", StringUtils.urlEncode(",", ",")); |
276 |
|
|
277 |
|
|
278 |
1 |
assertEquals("a%25b%3Dc%3Bd%3Ae%2C%2C", |
279 |
|
StringUtils.urlEncode("a%b=c;d:e,,", "=,;:%")); |
280 |
|
|
281 |
|
|
282 |
1 |
assertEquals("a=b", StringUtils.urlEncode("a=b", ";,")); |
283 |
|
|
284 |
|
|
285 |
1 |
assertEquals("a%3Db.c%3B", StringUtils.urlEncode("a=b.c;", ";=,")); |
286 |
|
|
287 |
|
|
288 |
1 |
assertEquals("a%3Db.c d", StringUtils.urlEncode("a=b.c d", ";=,")); |
289 |
|
|
290 |
|
|
291 |
1 |
assertEquals("a%3Db.c+d", StringUtils.urlEncode("a=b.c d", ";=, ")); |
292 |
|
|
293 |
|
|
294 |
1 |
assertEquals("a%3Db.c+d.e%3Df", |
295 |
|
StringUtils.urlEncode("a=b.c d.e=f", ";=,. ")); |
296 |
|
} |
297 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
298 |
1 |
@Test(groups = { "Functional" })... |
299 |
|
public void testUrlDecode() |
300 |
|
{ |
301 |
|
|
302 |
1 |
assertNull(StringUtils.urlDecode(null, ";,")); |
303 |
1 |
assertEquals("", StringUtils.urlDecode("", "")); |
304 |
1 |
assertEquals("", StringUtils.urlDecode("", ";,")); |
305 |
|
|
306 |
|
|
307 |
1 |
assertEquals("a%3Db", StringUtils.urlDecode("a%3Db", ";,")); |
308 |
|
|
309 |
|
|
310 |
1 |
assertEquals("a=b%3Ec; d", |
311 |
|
StringUtils.urlDecode("a%3Db%3Ec; d", ";=,")); |
312 |
|
|
313 |
|
|
314 |
1 |
assertEquals("a=b;c+d", StringUtils.urlDecode("a%3Db%3Bc+d", ";=,")); |
315 |
|
|
316 |
|
|
317 |
1 |
assertEquals("a=b%3Ec d=,", |
318 |
|
StringUtils.urlDecode("a%3Db%3Ec+d%3D%2C", ";=, ")); |
319 |
|
|
320 |
|
|
321 |
1 |
assertEquals("a,=;\t%z", |
322 |
|
StringUtils.urlDecode("a%2C%3D%3B%09%25z", ";=,\t%")); |
323 |
|
} |
324 |
|
} |