1   /*
2    * Copyright 2004-2009 the Seasar Foundation and the Others.
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,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.internal.util;
17  
18  import static org.junit.Assert.assertEquals;
19  
20  import org.junit.Test;
21  import org.seasar.cubby.internal.util.StringUtils;
22  
23  public class StringUtilsTest {
24  
25  	@Test
26  	public void replace() throws Exception {
27  		assertEquals("1", "1bc45", StringUtils.replace("12345", "23", "bc"));
28  		assertEquals("2", "1234ef", StringUtils.replace("12345", "5", "ef"));
29  		assertEquals("3", "ab2345", StringUtils.replace("12345", "1", "ab"));
30  		assertEquals("4", "a234a", StringUtils.replace("12341", "1", "a"));
31  		assertEquals("5", "ab234abab234ab", StringUtils.replace("1234112341",
32  				"1", "ab"));
33  		assertEquals("6", "a\\nb", StringUtils.replace("a\nb", "\n", "\\n"));
34  	}
35  
36  	@Test
37  	public void isBlank() throws Exception {
38  		assertEquals("1", true, StringUtils.isBlank(" "));
39  		assertEquals("2", true, StringUtils.isBlank(""));
40  		assertEquals("3", false, StringUtils.isBlank("a"));
41  		assertEquals("4", false, StringUtils.isBlank(" a "));
42  	}
43  
44  	@Test
45  	public void isNotBlank() throws Exception {
46  		assertEquals("1", false, StringUtils.isNotBlank(" "));
47  		assertEquals("2", false, StringUtils.isNotBlank(""));
48  		assertEquals("3", true, StringUtils.isNotBlank("a"));
49  		assertEquals("4", true, StringUtils.isNotBlank(" a "));
50  	}
51  
52  	@Test
53  	public void equalsIgnoreCase() throws Exception {
54  		assertEquals("1", true, StringUtils.equalsIgnoreCase("a", "a"));
55  		assertEquals("2", true, StringUtils.equalsIgnoreCase("a", "A"));
56  		assertEquals("3", true, StringUtils.equalsIgnoreCase("A", "a"));
57  		assertEquals("4", true, StringUtils.equalsIgnoreCase(null, null));
58  		assertEquals("5", false, StringUtils.equalsIgnoreCase("a", null));
59  		assertEquals("6", false, StringUtils.equalsIgnoreCase(null, "a"));
60  		assertEquals("7", false, StringUtils.equalsIgnoreCase("a", "b"));
61  	}
62  
63  }