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