blob: cf4800bd0c0dfd5fa7f8ca2b859186e095f62be9 [file] [log] [blame]
chrismair00dc7bd2014-05-11 21:21:28 +00001/*
2 * Copyright 2008 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16package org.mockftpserver.core.util
17
18import org.mockftpserver.test.AbstractGroovyTestCase
19
20/**
21 * Tests for the IoUtil class
22 *
23 * @version $Revision$ - $Date$
24 *
25 * @author Chris Mair
26 */
27class StringUtilTest extends AbstractGroovyTestCase {
28
29 void testPadRight() {
30 assert StringUtil.padRight('', 0) == ''
31 assert StringUtil.padRight('', 1) == ' '
32 assert StringUtil.padRight('z', 1) == 'z'
33 assert StringUtil.padRight(' z', 3) == ' z '
34 assert StringUtil.padRight('z', 1) == 'z'
35 assert StringUtil.padRight('zzz', 1) == 'zzz'
36 assert StringUtil.padRight('z', 5) == 'z '
37 }
38
39 void testPadLeft() {
40 assert StringUtil.padLeft('', 0) == ''
41 assert StringUtil.padLeft('', 1) == ' '
42 assert StringUtil.padLeft('z', 1) == 'z'
43 assert StringUtil.padLeft(' z', 3) == ' z'
44 assert StringUtil.padLeft('z', 1) == 'z'
45 assert StringUtil.padLeft('zzz', 1) == 'zzz'
46 assert StringUtil.padLeft('z', 5) == ' z'
47 }
48
49 void testJoin() {
50 assert StringUtil.join([], ' ') == ''
51 assert StringUtil.join([], 'x') == ''
52 assert StringUtil.join(['a'], 'x') == 'a'
53 assert StringUtil.join(['a', 'b'], '') == 'ab'
54 assert StringUtil.join(['a', 'b'], ',') == 'a,b'
55 assert StringUtil.join(['a', 'b', 'c'], ':') == 'a:b:c'
56
57 shouldFailWithMessageContaining('parts') { StringUtil.join(null, '') }
58 shouldFailWithMessageContaining('delimiter') { StringUtil.join([], null) }
59 }
60
61}