1bda3441225e0607b5ced8b538123fd7c7a417910chrismair/*
2bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Copyright 2008 the original author or authors.
3bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
4bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Licensed under the Apache License, Version 2.0 (the "License");
5bda3441225e0607b5ced8b538123fd7c7a417910chrismair * you may not use this file except in compliance with the License.
6bda3441225e0607b5ced8b538123fd7c7a417910chrismair * You may obtain a copy of the License at
7bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
8bda3441225e0607b5ced8b538123fd7c7a417910chrismair *      http://www.apache.org/licenses/LICENSE-2.0
9bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
10bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Unless required by applicable law or agreed to in writing, software
11bda3441225e0607b5ced8b538123fd7c7a417910chrismair * distributed under the License is distributed on an "AS IS" BASIS,
12bda3441225e0607b5ced8b538123fd7c7a417910chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bda3441225e0607b5ced8b538123fd7c7a417910chrismair * See the License for the specific language governing permissions and
14bda3441225e0607b5ced8b538123fd7c7a417910chrismair * limitations under the License.
15bda3441225e0607b5ced8b538123fd7c7a417910chrismair */
16bda3441225e0607b5ced8b538123fd7c7a417910chrismairpackage org.mockftpserver.core.util
17bda3441225e0607b5ced8b538123fd7c7a417910chrismair
18bda3441225e0607b5ced8b538123fd7c7a417910chrismairimport org.mockftpserver.test.AbstractGroovyTestCase
19bda3441225e0607b5ced8b538123fd7c7a417910chrismair
20bda3441225e0607b5ced8b538123fd7c7a417910chrismair/**
21bda3441225e0607b5ced8b538123fd7c7a417910chrismair * Tests for the IoUtil class
22bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
23bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @version $Revision$ - $Date$
24bda3441225e0607b5ced8b538123fd7c7a417910chrismair *
25bda3441225e0607b5ced8b538123fd7c7a417910chrismair * @author Chris Mair
26bda3441225e0607b5ced8b538123fd7c7a417910chrismair */
27bda3441225e0607b5ced8b538123fd7c7a417910chrismairclass StringUtilTest extends AbstractGroovyTestCase {
28bda3441225e0607b5ced8b538123fd7c7a417910chrismair
29bda3441225e0607b5ced8b538123fd7c7a417910chrismair    void testPadRight() {
30bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padRight('', 0) == ''
31bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padRight('', 1) == ' '
32bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padRight('z', 1) == 'z'
33bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padRight(' z', 3) == ' z '
34bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padRight('z', 1) == 'z'
35bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padRight('zzz', 1) == 'zzz'
36bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padRight('z', 5) == 'z    '
37bda3441225e0607b5ced8b538123fd7c7a417910chrismair    }
38bda3441225e0607b5ced8b538123fd7c7a417910chrismair
39bda3441225e0607b5ced8b538123fd7c7a417910chrismair    void testPadLeft() {
40bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padLeft('', 0) == ''
41bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padLeft('', 1) == ' '
42bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padLeft('z', 1) == 'z'
43bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padLeft(' z', 3) == '  z'
44bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padLeft('z', 1) == 'z'
45bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padLeft('zzz', 1) == 'zzz'
46bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.padLeft('z', 5) == '    z'
47bda3441225e0607b5ced8b538123fd7c7a417910chrismair    }
48bda3441225e0607b5ced8b538123fd7c7a417910chrismair
49bda3441225e0607b5ced8b538123fd7c7a417910chrismair    void testJoin() {
50bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.join([], ' ') == ''
51bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.join([], 'x') == ''
52bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.join(['a'], 'x') == 'a'
53bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.join(['a', 'b'], '') == 'ab'
54bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.join(['a', 'b'], ',') == 'a,b'
55bda3441225e0607b5ced8b538123fd7c7a417910chrismair        assert StringUtil.join(['a', 'b', 'c'], ':') == 'a:b:c'
56bda3441225e0607b5ced8b538123fd7c7a417910chrismair
57bda3441225e0607b5ced8b538123fd7c7a417910chrismair        shouldFailWithMessageContaining('parts') { StringUtil.join(null, '') }
58bda3441225e0607b5ced8b538123fd7c7a417910chrismair        shouldFailWithMessageContaining('delimiter') { StringUtil.join([], null) }
59bda3441225e0607b5ced8b538123fd7c7a417910chrismair    }
60bda3441225e0607b5ced8b538123fd7c7a417910chrismair
61bda3441225e0607b5ced8b538123fd7c7a417910chrismair}