1   /*
2    * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3    * Copyright (C) 2003-2008 Frederico Caldeira Knabben
4    * 
5    * == BEGIN LICENSE ==
6    * 
7    * Licensed under the terms of any of the following licenses at your
8    * choice:
9    * 
10   *  - GNU General Public License Version 2 or later (the "GPL")
11   *    http://www.gnu.org/licenses/gpl.html
12   * 
13   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14   *    http://www.gnu.org/licenses/lgpl.html
15   * 
16   *  - Mozilla Public License Version 1.1 or later (the "MPL")
17   *    http://www.mozilla.org/MPL/MPL-1.1.html
18   * 
19   * == END LICENSE ==
20   */
21  package net.fckeditor.tool;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertTrue;
25  
26  import java.util.HashSet;
27  import java.util.Set;
28  
29  import org.junit.Test;
30  
31  /**
32   * Tests for {@link Utils};
33   * 
34   * @version $Id: UtilsTest.java 1644 2008-02-27 18:09:53Z th-schwarz $
35   */
36  public class UtilsTest {
37  
38  	@Test
39  	public void getSet01() {
40  		Set<String> set = new HashSet<String>();
41  		set.add("a");
42  		set.add("ab");
43  		set.add("c");
44  
45  		Set<String> newSet = Utils.getSet("a|Ab|c", "|");
46  		for (String string : newSet) {
47  			assertTrue(set.contains(string));
48  		}
49  	}
50  
51  	@Test
52  	public void getSet02() {
53  		Set<String> set = new HashSet<String>();
54  		set.add("png");
55  		set.add("jpg");
56  		set.add("gif");
57  
58  		Set<String> newSet = Utils.getSet("png|jpg|gif");
59  		for (String string : newSet) {
60  			assertTrue(set.contains(string));
61  		}
62  	}
63  	
64  	@Test
65  	public void getSet03() {
66  		Set<String> set = Utils.getSet(null);
67  		assertTrue(set != null);
68  		assertTrue(set.isEmpty());
69  	}
70  
71  	@Test
72  	public void getSet04() {
73  		Set<String> set = Utils.getSet("");
74  		assertTrue(set != null);
75  		assertTrue(set.isEmpty());
76  	}
77  
78  	@Test
79  	public void replaceAll01() {
80  		String str = Utils.replaceAll("//a/b//c", "//", "/");
81  		assertEquals(str, "/a/b/c");
82  	}
83  
84  	@Test
85  	public void replaceAll02() {
86  		String str = Utils.replaceAll(null, "a", "c");
87  		assertEquals(str, "");
88  	}
89  
90  	@Test
91  	public void replaceAll03() {
92  		String str = Utils.replaceAll("foo", null, "c");
93  		assertEquals(str, "foo");
94  	}
95  
96  	@Test
97  	public void replaceAll04() {
98  		String str = Utils.replaceAll("foo", "o", "a");
99  		assertEquals(str, "faa");
100 	}
101 }